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