Recent Changes - Search:

Public

Physics

Engineering

Literature
Journal Club
People

MineralPET
DAQ

Computing

Africa


Command Line

Being able to use the command line well is a real bonus when using Linux. All of the commands below have a manual page where you can get more information. Type man command at the shell prompt.

Commands

CommandDescriptionExample
grep 
cutremove sections from each line of filescut
sedreplace #1 with #2 in filesed -i -e "s|#1|#2|" file
sort 
uniq 
findSearches for files in file systemfind . -name '*.C'
xargsreads arguments from the standard input, and executes the commandfind . -name '*.C' | xargs grep gMinuit

Examples

Example 1

grep mailer=local /var/log/maillog | grep "Mar 14" | cut -d',' -f1 | cut -d'=' -f2 | cut -d'@' -f1 | sed -e's/<//' | 
          sort | uniq -i | sed -e's/$/@src.wits.ac.za/'

will extract from the file /var/log/maillog lines that look like

Mar 14 23:30:27 schonlan sendmail[27155]: k2ELUGfh027154: to=<user@schonlan.src.wits.ac.za>, delay=00:00:03, 
          xdelay=00:00:03, mailer=local, pri=40038, dsn=2.0.0, stat=Sent
Mar 14 13:59:54 schonlan sendmail[24546]: k2EBwsfh024545: to=anotheruser, delay=00:01:00, xdelay=00:00:03, 
          mailer=local, pri=816326, dsn=2.0.0, stat=Sent

and turn them into a unique set of email addresses like
user@src.wits.ac.za

Example 2

To recursively delete only specific files ...... first check for the files you want to delete:

find /path_to_search -type f -name "*the_patern*"

and then, delete :

find /path_to_search -type f -name "*the_patern*" -exec rm {} \;

NB: the '\' and the ';' are important

Edit - History - Print - Recent Changes - Search
Page last modified on March 26, 2011, at 01:32 pm