Example: stock market

UNIX / Linux Shell Cheat Sheet

A full PDF and online tutorial is available at 7 Aug 2007 unix / Linux Shell Cheat SheetFile ManipulationTest OperatorsVariable Substitution> filecreate (overwrite) file>> fileappend to file # do something>file 2>&1both output and errors to file${V:?err}$V, or err if unset< fileread from filea | bpipe output from 'a' as input to 'b'Numeric TestsConditional Executionless thanc1 || c2run c1; if it fails, run c2 Common Constructsgreater thanc1 && c2run c1; if it works, run c2while read fequal todoread textnot equalCommon utilities and switches echo Line is $f file line greater or equallist files, biggest lastdone < fileby lineleless or equallist files, newest lastFile Testsdirectory sizes (slow)findnewer thansort -nsort numerically (not alpha)matchingdis a directorylist my commandslinesf is a filedownload URLrreadableget fieldwwriteabletouch filecreate filewith delimiterxexecutablerea

A full PDF and online tutorial is available at http://steve-parker.org/sh/sh.shtml v1.1 – 7 Aug 2007 UNIX / Linux Shell Cheat Sheet File …

Tags:

  Linux, Unix, Sheet, Teach, Shell, Unix linux shell cheat sheet

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of UNIX / Linux Shell Cheat Sheet

1 A full PDF and online tutorial is available at 7 Aug 2007 unix / Linux Shell Cheat SheetFile ManipulationTest OperatorsVariable Substitution> filecreate (overwrite) file>> fileappend to file # do something>file 2>&1both output and errors to file${V:?err}$V, or err if unset< fileread from filea | bpipe output from 'a' as input to 'b'Numeric TestsConditional Executionless thanc1 || c2run c1; if it fails, run c2 Common Constructsgreater thanc1 && c2run c1; if it works, run c2while read fequal todoread textnot equalCommon utilities and switches echo Line is $f file line greater or equallist files, biggest lastdone < fileby lineleless or equallist files, newest lastFile Testsdirectory sizes (slow)findnewer thansort -nsort numerically (not alpha)matchingdis a directorylist my commandslinesf is a filedownload URLrreadableget fieldwwriteabletouch filecreate filewith delimiterxexecutableread xread x from keyboardget outputString Testsof command=equal tozzero lengthn not zero lengthNetworking a)

2 Case is a goodlist all network interfacesway to avoidLogical Testsshow routers ;;iterating&&logical ANDlog in to host as user u b)through many||logical OR!logical NOT user u ;;constructs. *)Argument Variables$0program nameless filedisplay file, page by page ;;$1alias l='ls -l'create l as alias for ls -l $ list_of_filesfunction$9display a calendar (Mar 73)declaration$*all argumentsshow disk mounts}and calling$#No. of argumentstruss -p PIDsyntaxFiles: Contents / AttributesA for loopfind . -size 10k -printfiles over 10 Kbfor i in *iterates throughfind text filesdoits input (whichls all directories echo File is $i is subject todonesimple mathsbetter mathsUseful Variables bar in file$IFSI nternal File Separator$?

3 Return code from last programof each line$ Shell what Shell is running this script?LANGL anguage; C is US Englishfile with bar [ $x -lt $y ]; then${V:-def}$V, or def if unset${V:=def}$V (set to def if unset)filtgteqnegels -lSrls -ltrls -lhhuman-readable filesizes$ grep foo myfiledu -sk *afoontfoops -effoobarwget URLtime cmdstopwatch on `cmd`$ cut -d: -f5 /etc/passwdDilbertcmd | \cmd output to stdout andfoo=`ls` tee also to cmdrun cmd with low prioritycase $foo inifconfig -a echo foo is A netstat -rssh u@hostscp \copy to host as echo foo is B if/elif/elif/elif u@host:General Admin echo foo is not A or B 1st argument esac2nd argumenttar cf \create a tar archive from the listed dirs/filesdoubleit() {9th argumentcal 3 1973 expr $1 \* 2df -hshow syscalls of PIDdoubleit 3 # returns 6find.}

4 -name *.txt -printfind /foo -type d -lsunder /fooglobbing)three=`expr 1 + 2`echo "scale = 5 ; 5121 / 1024 | bcegrep (foo|bar) filefind foo orawk '{ print $5 }' fileprint the 5th wordsed s/foo/bar/g filereplace foo i


Related search queries