Posts

Showing posts from December, 2011

Few great UNIX commands & useful links

Following are the some advanced UNIX commands which i found very useful. DNS (Domain Name Service) host string Perform forward or reverse lookup on string dig @nameserver string Lookup string's host info from nameserver System Hardware Information grep -i memtotal /proc/meminfo Find total amount of RAM in the system dmidecode -q Display DMI/SMBIOS information cat /proc/cpuinfo Display CPU information egrep '(vmx|svm)' /proc/cpuinfo See if a processor supports hardware virtualization lspci -tv Display PCI information lsusb -tv Display USB information hdparm -i /dev/sda Display disk information for sda Quick HTML Editing Site Wide find . -type f -print -exec sed -i -e 's|X|Y|g' {} \; Replace all X's with Y's in all files this directory and below. perl -pi -w -e 's/X/Y/g;' *.txt Replace all X's with Y's in all files ending with *.txt find -name '*' | xargs grep 'string' Print filename and all lines containing ...

An interview question in unix, which is asked by most of the companies

Well, i was asked a question(which was last one)  write a shell script which renames all *.txt files in a directory to *.sh ? Immediately, mv command came into my mind as it does in many peoples' mind.Then i wrote like: find . -name "*.txt" -exec mv *.txt *.sh {}\;  however this was wrong. He told me to explain how the above would work and i realized this was not correct. then i tried something else like: find . -name "*.txt" -exec ls {}\; | perl -e '`rename *.txt *.sh`' I wasn't pretty much sure that this would work.He told thats fine if i could  try without perl. I asked for some hints and he reminded me of xargs & sh.Then i tried like: find . -name "*.txt" -exec ls {}\;| xargs -n1 sh -c 'mv $1 `basename $1 .txt`.sh' - and then i got selected in the unix rounds... :-) :-)  xargs is really a great unix command like sed & awk.It is quite often used for parallel processing.Never miss this if you  like t...