Linux & Unix Tricks

A few linux tips and tricks for newbies. I have made this page as a reminder of tricks I used in Linux or unix along the way.

To expand a .tgz of tar.gz file in one line :

gunzip < file.tar.gz | tar xvf -
gunzip < file.tgz | tar xvf -

To change both group and ownership recursively :

chown -R someowner.somegroup file

To search the entire hardrive for a file in Linux :

find / -name somefilename

To search on Linux within each file for some phrase on the entire harddrive and display the file and line numbers :

find / -exec grep -n “phrase” ‘{}’ \; -print

Xargs can be used to create a list of input file to one of your perl scripts e.g.

ls *.txt | xargs ./your_perl_script

Wc can be used to print the total bytes, words and lines in a file, combined with cat you can print a total number of lines or byte, e.g. say you want the total number of lines in all files in the current directory ending in .txt.

cat *.txt | wc -l

Display a range of lines withing a file where the starting line number is x and the ending line number is y :

sed -n ‘x,yp’ filename

Vim uses A4 paper size by default to change this, use the following setting for letter size :

:set printoptions=paper:letter

Submitted by Tyler McGinnis

Related posts:

  1. Some Unix Tricks
  2. 11 Unix Tricks
  3. Learn Unix in 10 minutes
  4. How To Detect Two Ethernet Cards in Linux
  5. Some Neat CSS Tricks

Filed Under: Linux and Unix

About the Author

Abhinav Kaiser is a certified project manager (PMP) and an expert in IT service management. He has been writing on several blogs for over 6 years and has been a source of inspiration for many budding bloggers. He recently started a blog, Abhinav PMP and his latest baby in the works needs special mention - Success Mantras. Click here if you need to get in touch.

Comments (2)

Trackback URL | Comments RSS Feed

  1. Peter says:

    If you’re using GNU tar (which all Linux distributions do) it’s even easier to untar a gzipped file:

    tar zxvf some.tgz

  2. Jonny says:

    Kinda short, and only giving noobs a hand full of one liners without actually showing them what pipes and redirected output does…

    No cookie for you!

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.