You are on page 1of 1

A full PDF and online tutorial is available at http://steve-parker.org/sh/sh.

shtml
v1.1 7 Aug 2007
UNI / !inu" #hell $heat #heet
File %anipulation &est 'perators (ariable #ubstitution
> file create (overwrite) file
>> file append to file # do something
>file 2>1 !oth output and errors to file "#$%&err' "$( or )err* if unset
+ file read from file
a , ! pipe output from -a- as input to -!- Numeri) &ests $onditional *"e)ution
less than c1 ,, c2 run c1. if it fails( run c2
$ommon $onstru)ts greater than c1 c2 run c1. if it wor/s( run c2
while read f e0ual to
do read te1t not e0ual $ommon utilities and s+it)hes
echo )2ine is "f* file line greater or e0ual list files( !iggest last
done + file !3 line le less or e0ual list files( newest last
File &ests director3 si4es (slow)
find newer than sort 5n sort numericall3 (not alpha)
matching d is a director3 list m3 commands
lines f is a file download 672
r reada!le
get field w writea!le touch file create file
with delimiter 1 e1ecuta!le read 1 read )1* from /e3!oard
get output #tring &ests
of command 8 e0ual to
4 4ero length
n not 4ero length Net+orking
a) case is a good list all networ/ interfaces
wa3 to avoid !ogi)al &ests show routers
.. iterating logical A9: log in to host as user )u*
!) through man3 ,, logical ;7
< logical 9;= user )u*
.. constructs.
>) Argument (ariables
"0 program name less file displa3 file( page !3 page
.. "1 alias l8-ls 5l- create )l* as alias for )ls 5l*
"2
... ... list?of?files
function "@ displa3 a calendar (Aar 7B)
declaration "> all arguments show dis/ mounts
' and calling "# 9o. of arguments truss 5p CD:
s3nta1
Files: $ontents / Attributes
A for loop find . 5si4e 10/ 5print files over 10E!
for i in > iterates through find te1t files
do its input (which ls all directories
echo )File is "i* is su!Gect to
done simple maths
!etter maths
Useful (ariables )!ar* in file
"DFH Dnternal File Heparator
"& return code from last program of each line
"HIJ22 what shell is running this script&
2A9K 2anguage. L is 6H Jnglish file with )!ar*
http%MMsteve5par/er.orgMshMsh.shtml
if N )"1* 5lt )"3* O. then "#$%5def' "$( or )def* if unset
"#$%8def' "$ (set to )def* if unset)
fi
lt
gt
e0
ne
ge ls 5lHr
ls 5ltr
ls 5lh human5reada!le filesi4es
" grep foo m3file du 5s/ >
afoo nt
foo ps 5ef
foo!ar wget 672
time cmd stopwatch on PcmdP
" cut 5d% 5fQ MetcMpasswd
:il!ert
cmd , R cmd output to stdout and
foo8PlsP tee file.t1t also to file.t1t
nice cmd run cmd with low priorit3
case "foo in
ifconfig 5a
echo )foo is A* netstat 5r
ssh uShost
scp file.t1t R cop3 file.t1t to host as
echo )foo is T* ifMelifMelifMelif uShost%
,eneral Admin
echo )foo is not A or T*
1
st
argument
esac 2
nd
argument tar cf t.tar R create a tar archive t.tar
from the listed dirsMfiles
dou!leit() # @
th
argument cal B 1@7B
e1pr "1 R> 2 df 5h
show s3scalls of CD:
dou!leit B # returns U
find . 5name )>.t1t* 5print
find Mfoo 5t3pe d 5ls
under Mfoo
glo!!ing) three8Pe1pr 1 V 2P
echo Wscale 8 Q . Q121 M 102X* , !c
egrep )(foo,!ar)* file find )foo* or
aw/ -# print "Q '- file print the Q
th
word
sed sMfooM!arMg file replace )foo* in

You might also like