Sunday, January 1, 2012

Interesting Linux commands

I found some very important linux command we can use in scripting and monitoring.

1) sed

This can be used to search and replace a text in file and print it on the screen as bellow

sed 's/regexp/replacement/' test.txt > test2.txt

2) watch

This command is used to execute same command in a periodic lay in the monitoring purpose.

watch -n 1 date

above command show date in every second in the console

3) grep

Search for a text and print matching lines

grep "sampath" test.txt
grep -e "sampath" -e "chandana" test.txt


4) cut

This can be used to cut line by line with given character positions

grep "sampath" test.txt | cut -c 1-2
grep "sampath" test.txt | cut -c 1-2,5,6

5) Find for a file

find ./ -name finename.ext

6) Find a files containing some text
grep -lir "text_need_to_find" ./

-l list file names
-r search recursivly in subdirectories
-i ignore case sensitive

7) Reintalling packages in ubuntu
sudo apt-get --reinstall install libaprutil1
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home