Tuesday, July 26, 2011

Helpful Unix Commands

Now I would like to give you the Unix commands which I use most of the time:

1) Search for a term in all the files in the current folder:
find . -type f -exec grep -l "search_term" '{}' \;

2) Find files in the current folder whose size is greater than 300K:
find . -size +300000k

3) Exchange xxx with yyy in all files ending with Temp.sh:
perl -pi -e 's/xxx/yyy/g' *Temp.sh

4) Cut lines between 125 and 127 from testfile (you can also redirect it to another file):
sed -n '/125/,/127/p' testfile

5) Kill all processes which includes xxx in its name:
kill -9 `ps -ef | grep "xxx" | grep -v grep | awk '{print $2}'`

Happy working!!

No comments:

Post a Comment