Linux & Unix Tricks

Posted by Shashank Krishna Friday, February 29, 2008


sharethis: 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

Reactions: 
Spread Firefox Affiliate Button | edit post .

0 comments

Post a Comment

Are You Planning on Quitting Facebook? Why?

@Flickr

www.flickr.com

About Me

My Photo
Shashank Krishna
Bangalore, up, India
nothin much to say.........doin B.tech in IIIT allahabad loves bloggingn hacking.... :) and loooves blogging
View my complete profile

ads2

topads