Technology weblog

IT-Essence
Thursday May 10, 2007

Command line commands in Linux

In this post I maintain a list of useful commands that can be entered at the Linux command line.

  • Look for a phrase in all files:
    $ find . -type f -print0 | xargs -0 grep phrase_to_find

  • Replace all occurences of a certain phrase in a collection of files:
    perl -pi -e 's/monkey/I am crazy/g' `grep -l monkey *`

  • Copy a directory and all its contents to another machine (preserving symbolic links!):
    tar cf - directoryToCopy | ssh user@remote.machine "cd destination; tar xvf -"

    In case there are more CPU cycles available than bandwidth, you may want to (un)compress while copying:
    tar cfz - directoryToCopy | ssh user@remote.machine "cd destination; tar xvfz -"

  • Listing of files sorted on size:
    ls -l . | sort -n -k 5,1

Comments:

Post a Comment:
Comments are closed for this entry.

Hire us
Archives
Tags
Links
Stats
Referrers