Linux cheat sheet

Posted by s1mple on Dec 30, 2008 in Linux, Tips & Triks |

- 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

Tags:

2 Comments

  • mr.bho says:

    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

  • s1mple says:

    thanks for the info mr.bho, it works.
    I am suck in awk and sed, will learn about it :(

Leave a Reply

XHTML: You can use these tags:' <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2012 Simple Difference All rights reserved.
Desk Mess Mirrored v1.4.3.1 theme from BuyNowShop.com.