Linux cheat sheet
- show disk usage: du
- show disk capacity: df
- search word from file inside directory:
find /start/dir -exec grep -q my_search_word {} \; -print
- search files with specific name inside directory (HP-Unix, maxdepth=1):
find . \( ! -name . -prune \) \( -name “*TEST1*.ps” -o -name “*TEST2*.ps” \) -mtime +30 -type f
find /parent/child \( ! -name child -prune \) \( -name “*TEST1*.ps” -o -name “*TEST2*.ps” \) -mtime +30 -type f
- display before+after line with matched specific pattern (Solaris):
nawk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];print;c=a}b{r[NR%b]=$0}' b=2 a=1 s="SEARCH_STRING" <file_name>
- display running process command args (Solaris):
pargs -a <pid>
/usr/ucb/ps -lawwx
just use grep:
$ grep -r -i [my_search_word] /start/dir/*
-r will search recursively
-i will ignores case-sensitives
you can use awk to print file_name only.
detail see man grep
find will index all files under /start/dir and after that throws as grep input before print to standard output.
cheers…
-bho
thanks for the info mr.bho, it works.
I am suck in awk and sed, will learn about it