Total Pageviews

Thursday, October 24, 2013

PS commands, listing process commands

$ps -ef | cut -c 1-70 | grep srinivas

Shows all the process with each line displaying first 70 characters of the output.
This shows all process which have srinivas in the output.


Sunday, May 19, 2013

Find with line number and excluding directory

find . -path ./excl_dir -prune -o -name *.c | xargs grep -n "SearchString" 2>/dev/null

This will exclude the excl_dir directory from searching.
The grep will SearchString with line numbers in the files where it is found.


Tuesday, April 9, 2013

Find or grep a string in a set of files

Find a string in a set of files:

$find . -name *.c | xargs grep my_func_name

        This command searches all the directories under the current directory for ".c" files.  In each of the file it searches for the string "my_func_name".  Lists out the matching files and string.

$find . -name *.[ch] | xargs grep my_func_name

        This command searches all the directories under the current directory for ".c" and "*.h" files.  In each of the file it searches for the string "my_func_name".  Lists out the matching files and string.

$find . -name *.[ch] | xargs grep my_func_name 2>/dev/null

        This command searches all the directories under the current directory for ".c" and "*.h" files.  In each of the file it searches for the string "my_func_name".  Lists out the matching files and string.
Also it does not print the error messages found during search on to the console.

$find . | grep Myfile | xargs grep my_func_name 2>/dev/null

        This command searches all the directories under the current directory for files containing "Myfile" in its name.  In each of the file found it searches for the string "my_func_name".  Lists out the matching files and string. Also it does not print the error messages found during search on to the console.

Wednesday, January 16, 2013

Find directories without "find: cannot open" messages



Command to find a directory (complete or part of name) named "srinivasbt" in all the directories under present "." directory.

$find . -name srinivasbt -type d

Same command as above which also avoids the unwanted messages of "find: cannot open ./"
This is by redirection of 2 helping in eliminating "find: cannot open ./nis.home/jaianshu/.subversion/auth"
kind of messages from the output.

find . -name srinivasbt -type d 2>/dev/null



find: cannot open ./


Command to find a file (complete or part of name) named "srinivasbt" in all the files and directories under present "." directory.

$find . -name srinivasbt

Same command as above which also avoids the unwanted messages of "find: cannot open ./"
This is by redirection of 2 helping in eliminating "find: cannot open ./nis.home/jaianshu/.subversion/auth"
kind of messages from the output.

find . -name srinivasbt 2>/dev/null

Friday, May 23, 2008

Search String in many files

The command to find string in many files:

srini@ openslp-1.2.1]$ find . -exec grep -q "427" '{}' \; -print
./common/slp_message.h
./config.log
./doc/rfc/rfc2614.txt
./doc/rfc/rfc2608.txt
./doc/rfc/rfc2165.txt

Thursday, May 22, 2008

SIOCADDRT: Invalid argument

According to the usual man pages, the following command should add the normal loopback entry, using netmask 255.0.0.0 and associate with the "lo" device.

But I got an error when trying on a linux system with linux kernel 2.6.x

#route add -net 127.0.0.0


#SIOCADDRT: Invalid argument

I could fix this by using the additional arguments to the "route add" command

#route add -net 127.0.0.0 netmask 255.0.0.0 lo

and it worked...

Now the "route -n" shows the added loopback route..