You are on page 1of 19

Uni

xBas
ics

Hi
sto
ry
ThefirstversionofUni xwa sdeve lopedb yBe l
lLa bs( par
tofAT&T)i n1969,ma ki
ngitmor ethan
fort
yy earsolda ndoneoft hefewc a sesofac omput e rtechnologythatha ssurvi
vedmor ethana
decade .I
tsrootsgoba cktowhe ncomput erswe r
el a
r gea ndrare,ti
meont hemv eryexpensi
vea nd
sharedbe tweenma nyusersUni xwa sde s
ignedfrom t hebe gi
nning1 t
oha vemul t
ipl
euserswor k
ing
simultaneousl
y.Whi l
ethismights eems t
rangea ndunne cess
aryinawor l
dwhe reevery
oneha sthe i
r
ownl aptop,comput i
ngisa gai
nmov ingba cktor emot ec entra
ls er
vic
eswi t
hma nyuser
s:thec ompute
powe rrequir
edf orma ppingnext-gene rat
ions e
que nci
ngda taordenov oassemblyisbeyondwha tis
avail
ableorde si
ra bl
et ohavesitti
ngony ourl a
p.Inma nywa ys,theCloud(orwha teverhasreplace
d
i
tb yt het i
mey our eadthis)requir
eswa ysofwor kingt hataremor einc ommonwi thtr
aditi
onalUnix
ma chinesthant hepe rs
onalcomput inge mpha si
sedb yWi ndowsa ndAppl eMa ci
ntosh.
USAf ede r
almonopol ylawp r
eventedAT&T f rom c omme rci
ali
si
ngUni xbutinte r
e stinus ingit
i
nc reasedout si
deofBe llLabsa nde ventual
lytheyde ci
de dtogi v
eita wa yfreel
y,i
nc ludingt hes ource
code ,whicha l
l
owe dot heri
ns t
ituti
onst omodi f
yi t.Perhapsthemos timpor ta
ntoft he s
ei nstit
utions
wa st heUni ver
sityofBe rkel
ey2
whichdistri
butedas etoft oolstoma keUni xmor eus e f
ula ndma de
cha ngestha tsignific
ant l
yincreasedpe rf
orma nce.Thei nvolv
eme ntofs everaluniversi
t i
esini ts
deve l
opme ntme antUni xwa sideal
lyplac e
dwhe nt heinternetwa screa t
eda ndma nyoft he
funda menta ltechnologi e
swe rede v
elopeda ndt estedus i
ngUni xma chines.Againt hesei mp roveme nt
s
we regivena wa yfre el
y,someoft hec odebe i
ngr epurposedtop rovi
de dne tworki
ngf ore arlyv er
sionsof
Wi ndowsa nde vent oda yseveraluti
li
tiesinWi ndowsVi s
taincorpora
t eBe rkel
eycode 3
.
Aswe llasbe ingakeypartint hedeve
lopme ntoftheearlyint
ernet
,aUni xma chinewasa l
sot he
firs
twe bs erv
er,aNe XT cube.Ne
4
XT wasane arl
ya t
temptt oma keaUnixma c
hinefordesktopuse,
ex t
remelya dvanc e
dfori
tstimebuta l
soveryexpensi
vesot heyneverrea
ll
yc aughtonout si
deoft he
financeindustry.Appl
ee v
entuall
yboughtNe XT,i tsoper
ati
ngs yste
m becomingOs X,a ndthis
he r
ita
gec a
ns ti
llbeseeninitsprogramminginterf
aces.Appleisnowthelargestma nufac
turerofUnix
ma chine
s ;everyApplecomput er
,t hei
Phonea ndmos trecentiPodshaveaUni xba s
eunde r
ne at
h
theirfacade.
Byt heea
rly90sUnixbecameincr
ea s
ingl
yc ommerci
al
lyimporta
ntwhic
hinev
itablyleadtole
gal
t
rouble
:wit
hs oma nypeopl
egivi
ngawa yimp r
ovementsfr
eel
ya ndhavi
ngthe
mi nt
e grat
edintothe
s
ystem,whoa ct
ual
lyownedit?Thele galtr
oublecas
tuncertai
ntyove
rthefr
eel
yav ail
abl
eUnix
v
ersi
ons,cr
eati
nga nopeni
ngforanotherfreeoper
ati
ngs y
stem.
Thev
acuum wa
sfil
l
edb
yLi
nux
,af
ree
lya
vai
l
abl
ecomput
erope
rat
ings
yst
em5 s
imi
l
art
oUni
xand
1 Thisislie.Int ruth,Unixactual
lygrewoutofade si
ret opl
ayaga mecal
ledSpaceTr av
el
htt
p://e n.wikipedia.
org/wi
ki/Space
_Tra v
el_(vi
deo_ga me)a ndthefeat
urestha
tma dei tanoper
ati
ng
sys
tem we r eincidental
.Ini
ti
all
yitonlys
upportedoneus erandt henameUnix,ori
gina
ll
yUNICS,i
san
unf
o r
tuna tepunonMULTICS,amul t
i-
usersys
tema va
il
a blea
tt het i
me.
2 As i
gnificantp roport
ionofMa cOs Xhasitsrootsi
nt heBe rk
e l
eyStanda
rdDistr
ibuti
on( BSD).
3 Forexa mpl e:s trings ftp.exe | grep Cal
@(#) Copyright (c) 1983 The Regents of the University of California.
4 Seehttp://e
n.wikipedi
a.org/wi
ki
/NeXT
5 Morec orr
ectl
y,Linuxisjusttheker
nel
,thec
entr
alpr
ogramfr
om whi
challot
her
sarer
un.Ma nymor
etool
s
i
na ddi
tiontot hi
sa rerequir
edtomakeanoper
ati
ngsys
tem,tool
spr
ovi
dedbytheGNUp r
oje
c t
.
ht
tp://www. gnu.
o rg/.
sta
r tedb yLinusTorva l
dsin1991a sahobb y.Importa nt l
y,Linuxwa swr i
ttenf r
om s cr
atcha nddidnot
cont ainanyoft heori
ginalUni xcodea nds owa sfreeofl egaldoubt .Coi nc i
dingwi ththepe net
ration
oft hei nt
ernetontouni v
ersi
tyc ampusa ndt hea v
a i
l
a bil
ityofc he apbuts uffici
ent l
ypowe r
fulpersonal
comput er
s,Linuxrapi
dlyma t
ure dwithov eronehundr edde velopersc ollaborati
ngov erthei nt
ernet
withint woy ear
s.Ther ealadva ncesdrivingLi nuxwe res ocialr
a thert hant e
chnol ogical
,disparat
e
vol
unt eer
sdona t
ingti
meont heunde rsta ndingtha t
,i nr eturnf orgivingt he i
rwor ka wa yfreel
y,
anyt hingbasedont heirworkisa lsogiv ena wa yfree
lya nds ot heyint urnbe nefitf r
om imp rove
me nts.
Thei deathatunderpinsthissha r
inga nde nsuresthatnobodyc anp rofitfrom a ny oneelse'
swor k
withouts hari
ngi s
cop yl
eft
,de scri
bedi nas implelega ldoc ume ntc alledt heGNUGe neralPubli
c
Licenc ehttp:
//www. gnu.org/cop yl
eft
/ whi
6
c hturnst henot i
onofc op yri
ghtoni tshe ad.
Today
,Linuxha
sbe c
omethedomi
nantf
reeUni
x-l
i
keope
rat
ings
yst
em wi
thmi
l
li
onsofus
ersa
nd
s
upportf
rom manyla
rgecompa
nie
s.

Ge
tti
nga
ndi
nst
all
i
ngUbunt
u
Thistutori
alconcentr
ate sontheUbuntudist
ri
buti
on(pac
k agi
ng)ofLi
nux,whichisoneoft he
mostwidel
yus ed,butallthee x
amplesar
efairl
ygener
icandshouldworkwit
hmos tLinux,Uni
xa nd
Macint
oshc omputers
.The rea r
ema nydi
ffe
rentgui
desonthewe babouthowtoinstallUbunt
ubut
werecomme ndinstal
l
ingita sav i
rt
ualmachineonyourc
urrentcomputer
,seese
pa r
ate
doc
ume nta
t i
onforinstr
uctions.
TheUbunt uLinuxdi
stri
buti
onisge ne r
all
yea s
yt ouseanditisupdate
d( f
orf ree
)e verysixmonths.
Atthetimeofwr i
ti
ng,thecurre
ntve rsionofUbunt uis11.
10,name daft
eri tsreleas
eda teinOc tobe
r
2011,anda l
soknownasOne i
ri
cOc elot
;thene x
tv e
rsi
on,12.04orPreci
s ePa ngol
inwillbe
rel
eas
edinAp ri
l2012andwi l
lbedesigna tedaLongTe r
m Support(LTS)e dit
ion,me a
ningthatitwil
l
berecei
vefix
esandma i
ntenanceupgra desforfiv
ey ea
rsbefor
ebe i
ngreti
red,a ndist hebe s
topti
oni f
youdon'twanttoberegular
lyupgradingy oursyste
m.

Ac
cli
mat
isa
tion
As ignificantefforthasbeenunde rtakent oma keUbunt ueasyt ous e,soe vennov i
cec omput er
user
ss houldha vel i
ttl
et r
oubleusingit.The reisac onsiderabl
enumbe roftutorialsa v
ail
a bleforuser
s
newt oUbunt u;theoffici
alma ter
ialisavaila
blea tht tps://hel
p.ubunt u.c
om/11. 10/butaqui ck
sear
c hont hewe bwi l
llocat
emuc hmo re.Ina dditi
on,t he r
eisal otofdoc ume ntationinsta l
le
dont he
ma c
hi neits elf
:youc a nacces
st hi
sb ymov ingt hemous et owardsUb untuDe sktopa tthet opl e
ftof
thes creena ndcli
ck i
ngont hehe l
pme nut hata ppears.Inge neral
,t hena meoft hep r
ogra my ouare
curr
e ntlyus ingisdi s
playe
da tthet op-l
eftoft hes creena ndmov i
ngt hemous et ot opoft hescree
n
wil
lre vealt hep r
ogr amsme nusinas i
milarfashiont ohowt heya redi spl
ayedont heMa c( alt
hough,
confusingly,s omep r
ogramsdispla
yt heirme nuswi thinthe i
rownwi ndowr at
herl i
k eaWi ndows
comput er
).
Ana lt
erna
tiv
ewa ytoge thelpistocl
ickontheci
rcul
arsymbol(asty
li
sedpi
ctur
eoft hreepe
ople
hol
dinghands)att
het opleftoft hes
cre
ena ndty
pehe l
pinthesea
r c
hboxthatappea
rs.Forwa ntof
abettername,wewillre
fert othepeopl
e-hol
di
ng-
handsbutt
ona stheUbuntubutt
onalthoughthe
hel
pt e
xtthatappe
arsde s
cribesitasDas
hhome
.
Ubuntucomesfre
ewithma nyt ool
s,inc
ludingwebb r
owser
s ,fil
emanager
s,wordproc
essor
s,et
c.
Genera
ll
yther
eisafreeequi
valentformosts oft
wareyoumightus eandyoucanb r
owsethose
av
a i
l
ablebycl
ic
kingontheUb untuSoftwareCe ntr
e,whoseicona tthel
eftofthescr
eenlooksl
i
kea
6 I
tshoul
dbenot
edt
hatt
heGNUp
roj
ect
,andt
hephi
l
osophybe
hindi
t,p
reda
teLi
nuxb
yal
mos
tade
cade
.
shoppingba gfullofgoodie
s.TheUbuntuSoftwar
eCe nt
reisjustastar
ti
ngpointa ndt herea
remany
others ourc
esa v
a i
la
ble,bothofpr
epac
k a
gesoftwar
especi
fic
all
yforUbuntuands ourc
ec odet
hatwi
ll
requi
rec ompil
ing.Se a
rchthewebforUbunt
us of
twar
ereposit
ori
esf
ormoreinformationonobtai
ning
addit
iona ls
oft
wa re.
Whi lethe reareexpl
ici
tkeycombi
nati
onsf orcopyandpa s
tingtex
t,justl
ik
eonWi ndowsorMa c,
shi
ft-
control -
ca ndshif
t-c
ontr
ol-
vinUbunt u,thi
sconvent
ionisnotrespect
edbya l
lp r
ograms.Uni
x
hastradit
iona l
lybeenmor emousecent
redwi ththelef
tmousebut t
onus edtohi
ghlighttextandthe
middl
ebut t onus e
dt ocopyit
.Youma yfindyoursel
facci
dentall
ydoi
ngt hi
socca
sionall
yifyouare
n't
usedtous ingt hemiddlemousebutt
on.
Star
ti
nga ppli
cati
onsfr
om icons,openingfol
ders,etc
...onlyrequi
resasingl
ec l
ic
k,ratherthant he
doubl
ecli
ckrequire
donWi ndows ,makingthea c
tionofp ress
ingbuttonsands el
ect
ingthingsfr
om
menusmorec onsi
stentwi
theac hother.Acci
dentall
ydoublec l
ick
ingwillgener
all
yresul
tina nac ti
on
bei
ngdonetwic e
,notnormall
yaba dthingbutitdoe sme ansthatimpati
entuserscanquicklyfind
thei
rdes
ktopc over
edinwindows.
Pe rhapsthemos timport antdi
ffer
enceyoua r
eli
kel
ytoencounteronada i
l
ybasi
sisthatthe
name soffil
esa nddir
ectori
e sarecasesens
iti
ve:README.txt
,r e
adme .t
xtandre
adme.TXT allr
efe
r
todiffer
entfil
es.Thisisdiffere
ntfrom bot
hWi ndowsandMacOs X7,wher
euppera
ndl ower
-cas
e
char
a cter
sarep re
serve
di nt henamebutt hefil
ec a
nberef
err
e dtous i
nganycas
e.

Fe
tchi
ngt
hee
xampl
es
Therea remanyexa
mpl esi
nt hi
st utor
ialtobetr
ied,encl
ose
dinbox esl
iket
heonebelo
wwhich
expla
inst hefor
matofthee xamples.Thefile
srequi
redfortheexa
mpl e
sc a
nbedownloa
dedfrom
http:
//tinyurl
.c
om/32a2gbk/uni
x .
tgza l
thoughtheexamplebel
ows howshowtoautomati
cal
l
y
downloada ndunpackthefil
ereadyf oruse.
# Ordinary text, starting with a # and indented on the first line, is a comment
# on the example.
Bold text is something to type in at the command-line. A single
line wrapped on to multiple lines is indicated by the ' ' symbol
This is now a separate command.
Italic text is a reply from the computer to what was typed in
# Now we will download and install the examples
# Firstly, ensure that we are in the home directory
cd
# Where an example requires you to be in a specific directory, it will start
# with the command and reply to tell you where you should be. If you are not
# in the correct directory, move to it before doing the example (see later for
# how to change directory. Here 'ebi' is just the name of the user (you),
# yours may vary.
pwd
/home/ebi/
# Download and unpack the examples. You don't need to understand what this is
# doing yet, although you will by the time you have worked through this
# document.
wget -O - 'http://tinyurl.com/32a2gbk/unix.tgz' | tar -zx
# If you are trying the examples out on a Mac, the command wget is not

7 De
spi
teit
sUnixher
ita
ge.Thi
sbe
hav
iouri
sde
li
ber
atet
oma
int
ainc
ompa
tibi
l
itywi
the
arl
i
erv
ers
ionsoft
he
Macope
rati
ngsy
stem.
# available and the above will not work. Instead, use the similar curl command
curl -L 'http://tinyurl.com/32a2gbk/unix.tgz' | tar -zx
# A directory `examples' should have been created.
ls examples/unix
CompressionLineEndings MultipleFiles SCP haiku
Escaping MoveCopy Pipes Scripting
# How to delete the examples, if required
# Firstly, ensure that we are in the home directory (where the examples where
# installed).
cd
rm -rf examples

Thec
omma
ndl
i
ne
Whi l
eUbunt uhasa l
lthegr a phi
caltoolsy oumi ghte xpectinamode rnope rati
ngs yste m,s one w
usersra r
e l
ynee dtodea lwithitsUni xfounda tions,wewi llbewor ki
ngwi ththec omma nd- line.An
obviousque sti
oni swhyt hec omma nd-l
ineiss til
lthema inwa yofi nter
acti
ngwi t
hUni xor ,mor e
rel
evant l
y,whywea rema k
ingy ouus ei t?Pa rtoft hea nswe rtot hefir
stquestionist hatt heor i
ginsof
Unixp reda t
et hedevel
opme ntofgr aphicalinterf
a c
e sandt hi
si swha tal
lthetool sandp rogr amsha ve
evol
v edf rom.Ther easont hec omma nd-li
ner ema i
nspopul aristhatitisane xtreme l
ye fficientwa yto
i
nterac twi t
ht hecomput er:onc eyouwa ntt odos ome thingc omplexenought hatt herei sn' taha ndy
buttonf orit,graphi
calinterfac
e sforcey out ogot hroughma nyme nusandma nual
lype rform at ask
thatc ouldha vebeena utoma ted.Alternativel
y,y oumus tr es
orttos omef orm ofp r
ogr ammi ng(Ma c
Os XAut oma t
or,MicrosoftOffic ema cros,etc)whi chi st hemor alequiva
lentofus i
ngt hec omma nd-
l
ine.
Unixisbui
ltaroundma nylit
t l
etool
sde si
gnedt oworkt ogethe
r.Eachprogram doe sonet as
kwe l
l
andreturnsitsoutputinaf or
me as
il
yunde r
stoodb yotherp r
ogramsandthesep r
ope rti
esa l
l
ows i
mple
progr
a mstobec ombi nedtogethertoproducec omple
xr e
sults,rat
herl
ikebuil
dings omethingoutof
Legob ri
cks.Thef or
wa r
dtot he1978r e
por ti
nt heBe l
lSys t
em Te c
hni
calJournal
8
descri
bestheUnix
phil
osophya s
:
"(
i)Ma k
eeac
hp r
ogr
am doonethi
ngwe
ll
.Todoane
wjob,bui
l
daf
res
hra
the
rtha
ncompl
i
cat
e
ol
dprogr
amsbyaddi
ngnewfea
ture
s.
(i
i
)Ex pectt
heout putofever
yp r
ogramtobe c
ometheinputtoanothe
r,asyetunknown,pr
ogr
am.
Don'
tclutt
eroutputwithextr
aneousinf
orma
tion.Av
oidst
ringe
ntl
ycolumnarorbina
ryinputf
ormat
s.
Don'
tinsi
stoninter
ac t
ivei
nput.
(i
ii
)De
signandbui
lds
oft
wa r
e,eve
noperat
ingsyst
ems,t
obet
ri
ede
arl
y,i
dea
ll
ywi
thi
nwe
eks
.Don'
t
he
sit
atetothr
owa wa
ytheclumsypart
sandrebui
l
dt he
m.
(i
v)Us
etool
sinp
refe
renc
etounsk
il
le
dhe l
pt ol
i
ghte
nap r
ogra
mmi ngtask
,e v
e ni
fyouha
veto
de
tourtobui
l
dthetool
sandex
pecttothr
ows omeofthe
m outaf
teryou'
vefini
shedusi
ngt
hem.
"
Ther
estoft
histut
oria
lwillbeba
sedus
ingthec
omma nd-
li
nethr
oughater
mina
l9
.Thet
ermina
l
p
rogr
amcanbefoundb ycli
cki
ngontheUbunt
ubuttona
ndt ypi
ngter
mina
linthes
ea rc
hbox,as

8 See:M. D.Mc Il
roy
,E.N.Pins
on,andB. A.Tague"UnixTime-Sha
ringSy
ste
m For
ward",TheBel
lSyst
em
TechnicalJounal
,July-Aug1978v ol57,number6part2,pg.1902
9 Terminologythatdatesbacktothee ar
lyday
sofUnixwhe nther
ewouldbemanyt
e r
minal
s
,ba
sic
all
ya
fa
ncys creenandk ey
board,conne
ctedtoac ent
ralc
omput e
r.
showni
nIl
lus
trati
on1.Onceopen,thet
extsi
zecanbechangedus
ingtheVi
e om me
w/Zo nuopt
ions
orthef
ontchangedent
ir
elyus
ingtheEdi
t/Pr
ofil
ePre
fer
encesmenuopti
on.
Whi l
ewea r
eus i
ngLi nuxduringthewor kshop,y ouma ynotha v eac c
e s
stoama c
hinela t
erorma y
notwi sht ouseLi nuxe xcl
usi
velyony ourcomput er.Whiley oucouldinstal
lLinuxa s'dual-
boot'on
yourc omput er
,orr uni tinav i
rtualma c
hine ,t
10
hek nowledgeoft hec omma nd-li
neisfair
ly
transf
e r
ablebetwe enpla tf
orms:ha vi
ngUnixf ounda ti
ons,Ma cOsXa lsoha sac omma nd-l
inehidden
awa y:/Appl i
cations/Ut i
li
ti
es/Terminaland,wi thas ma l
lnumbe rofe ccentri
ci
ties,ever
ythingthat
wor k
sont heLinuxc omma nd-l
ineshouldwor kf orOs X.Wi ndowsha sitsowni ncompa ti
blevers
ionof
ac omma nd-l
i
nebutCy gwinhttp://www.cygwi n.com/c anbei nstal
leda ndprovidesane ntir
eUnix-
li
ke
envir
onme ntwithinWi ndows .

Il
lustrati
on1:Op eningaterminalinUb untu.A p art
ial
lyobscuredt ermi naliss hownatt heb ot
tom
ri
g htofthede sktop.
Att hebe gi
nni ngoft hecomma nd-l
ineist hec omma ndp r
ompt ,s howingt hatt hec omputerisready
toa cceptc omma nds.Thepromptistextoft hef or
m user@computer:directory$,I l
lus
trati
on1
hav i
ngaus erc all
e dtiminthedire
ctor
y~onac omputercall
edc offee-gri
nder.Ha vi
nga l
lthis
i
nforma ti
oni sha ndywhe nyoua r
ework i
ngwi thmul t
ipl
eremotec omput ersatt hes amet i
me .The
prompti sc onfigur abl
eandma yvarybe t
we enc omputer
s;youma ynot i
cel aterthatot herpromptsare
sl
ightlydiffer
ent .Someba s
iccomma ndsa res howni nTable1;t r
yt ypingt hema tthec omma nd-l
ine
11

p ressreturna f
te rthecomma ndtote l
lthec omputertorunt hec omma nd.

10AVirtualMachi
ne( VM)isap r
ogram onyourcompute
rthatactsli
keanothe
rc omputerandcanr
unother
oper
atingsys
tems.Sever
alVM' sar
eav a
il
abl
e,Vir
tual
Boxhttp:
//www. v
irt
ual
box.or
g/isfreeandr
egul
arl
y
updat
ed.
11You'
llnoti
cethattheoutputofpwddoesnotagreewitht
hec omma ndprompt,ins
tea
dp ri
nti
ng
/home/ebi. Thisisbecause~isasynonymfor/home/ebi,s eeTable2formo r
ede t
ail
s.
whoami Yourus
erna
me
hostname Na
meofma
chi
nebe
ingus
ed
pwd Cur
rentdi
rec
tor
y(Pr
intWor
kingDi
rec
tor
y)
uname Ope
rat
ings
yst
em(
uname -af
ort
hef
ullde
tai
l
s).

Tabl
e1:Someb as
iccommandstoanswertheimpor
tantq
ues
tionsofl
if
e:
whoam I
?,
whe
ream
I?
,andwhatoper
ati
ngsy
stem am Irunni
ng?

Fi
l
esa
nddi
rec
tor
ies
Allfil
esinUni xarea rrange dinat re e-l
ikes tr
ucture
:dire
ctori
esa r
er epre
s e
nte dasbranchesleading
fr
om as ingl
et runk( t heroot)a ndma y,int urn,haveotherbranchesleadi
ngf rom them(di r
ectories
i
ns i
dedi rect
or i
e s
)a ndi ndi
v i
dua lfil
esar ethel eavesofthetree.Thet rees t
ructureissi
mila
rt ot hatof
everyot hercommonope ratings ystema ndmos tfil
ebrowserscandispla
yt hefil
e sys
teminat r
ee-lik
e
fa
s hi
on,f orex ample :pa r
toft hefil
esyste mf ora nUbuntuLinuxc omput e
ri sdispla
yedinIl
lustr
at i
on2.
Whe reUni xdi ffer
sf rom othe rope rat
ings yste msisthatthefil
esyste
mi sus edmuc hmorefor
organis
ingdi fferentty pesoffiles:thee ss e
ntials y
stemp r
ogramsa realli
n/bina ndthei
rsha r
edc ode
(l
ibrari
es)a r
ei n/lib;s i
milarl
yus erp rogramsa rein/usr/bin,withlibrar
iesin/usr/liba ndma nual
pagesin/usr/share/man.
The rearetwodi
ffer
entwa y
sofspecif
yi
ngt helocati
onofafil
eordi
rect
oryi
nt hetree
:the
absolut
epa t
ha ndt
her el
ati
vepathfr
om whe rewec urre
ntl
yare(t
hecurr
entworki
ngdirect
ory
,se
e
pwd,p r
evi
ously
)inthefil
esy
stem.Ana bs
olutepathisonethatstar
tsa
ttheroota nddoesnotde
pend
ont heloc
ationoft
hec urr
entworki
ngdirect
ory.Sta
r t
ingwit
ha/t osi
gnif
ytheroot,thepath

Il
lust
r at
ion2:Tree-l
ikes
truct
ureoftheUb untufil
esy
stem.Start
ingattheroot'/'
,dire
ctorie
sar
e
di
s pl
ay e
dandt hehomeandhome /t
im di
rect
orie
shav ebee
nop enedtoshowitsconte
nts,
rel
ationshi
psindic
atedbyindent
ion./home/ti
mc ont
ainssev
eralmoredire
ctori
eswhichc oul
dal
so
beope ned.
describesallthedi rec
tor
ies(br
anches)wemus ttrave
r s
et ogettot hefil
e,eachdirec
toryname
separa t
edb ya/.Fore x
ample,/home/user/Music/TheKinks/SunnyAfternoon.mp3r efer
stot hefil
e
Sunny Afternoon.mp3i nsi
dethedirec
toryThe Kinks,whi chisinsi
det hedire
ctoryMus i
c, ,whichis
i
ns i
deont hedi rector
yhome ,whic
hisc onnect
e dtot her oot.Ifyoua r
ef a
mi l
i
a rwi
thMi cr
osof
t
Wi ndows ,youmi ghtnoti
cethatthepa t
hs e
pa rat
orisdi ffe
rent:aforward-s
lash/r at
herthanthe
bac kward-sl
as h\onWi ndows;thepathsofwe bpa gesa rea l
soseparatedbyf orwa
rd-s
las
hes,r
e v
e a
li
ng
theirUni xoriginsasapa thtoafileonar emot ema chine .
Forc
onv
enienc
e,afewdir
ect
ori
esha
ves
pec
ials
ymbol
stha
tar
esy
nony
msf
ort
hema
ndt
hemos
t
c
ommonoft he
sea r
eli
ste
dinTabl
e2.
Sy
mbol De
scr
ipt
ion Not
es
/ Rootdi
rec
tor
y Got
otopoft
ree
. Cur
rentdi
rec
tor
y
.. Thepa
rentdi
rec
tor
y Gouponei
ntr
ee
~ Homedi
rec
tor
y Sy
nony
mfor$HOME
~user Homedi
rec
tor
yforuser

Table2:Spe c
ialdi
rectoryname s
.Mostoft hetheseareonlyhaveaspecia
lmeaningwhe natt
he
begi
nningofapa th,ot her
wisetheyar
ejustas ymbol.Forexample
,dir/~/isthedirect
ory~ i
nsi
de
thedirec
torydirint hec ur
rentdir
ect
ory
,whe reas~/dir/isthedir
ect
orydirinsidethehome
dir
ector
y.Inbothc as
e sthe'/'symbol
sares epa
rator
sr at
herthantherootdi
rec
to r
y.

Thec ur r
entl ocati
on,t hewor k i
ngdi rector
y,c anbedi splayedatt hec omma nd-l
ineus ingthepwd
comma nd.Ra the rthanr efe
rri
ngt oafileb yitsa bsol
utepa th,wec anr eferitb yusingapa threlati
ve
towhe rewea re:afil einthec urre ntdirector
yc anber e f
er redtobyi tsna me ,afilei nadi rector
y
i
nsideourwor kingdi rect
oryc anber eferredtob ydirectory/filename( a nds oonf orfilesi
ns i
deof
dir
e c
toriesinsi
deofdi rect
oriesinsideofourwor ki
ngdi r
e ctory,et
c...).Not et hatthe sepa thsarev ery
si
mi l
art ohowwede scri
bea bsolutepa thse xceptthatt heydonots tar
twi th/;a bsol utepathsare
rel
ativepa thsrelativetot heroot( al
ternativel
ywec oul
dr e adthei niti
al/a sgotor ootandc onsider
themt ober el
a tivepa t
hs).Ass howni nTa bl
e2,t hedir e
c toryabov ethec urre
ntdi re ct
oryca nbe
ref
e r
redt oa s..s o,ifthewor kingdi rectoryis/home/user,t he
nt her ootdi rectoryc a nbereferr
e dto
as. .
/..(gouponedi re
ctory,the ngoupa notherdirect
or y).Thes ymbol. .c a
nbef r eel
ymi xedinto
paths:thedi re
c toryexamplesbe lowt hec urrentdirec
toryc oul
dha vepa th
examples/../examples/../examples( needles
st osay,s implyusingj ustexamplesi s
recomme nded).

Comma
nds
Commandsar
ejustpr
ogr
amsel
sewhe
reont
hecomputera
ndent
eri
ngt
hei
rna
meont
he
c
omma nd-
li
ner
unsthem.Comma
ndshaveapr
edi
cabl
efor
mat:
command -flags target
Thec omma ndi
sthena meoft heprogr
a mtorun,the(opti
ona l
)flagsmodifyi
tsbeha
viourandthe
ta
rgetiswha tthecomma ndi
st oope ra
teon,oftenthenameofafil e
.Ma nycommandsrequi
re
nei
therflagsnorta
rgetbutUnixt ool
saregener
a l
l
ye xt
remel
yc onfigurabl
eandeve
ns i
mplecomma nds
l
ikedate ha
12
vema nyopti
onalfla
gst ochangetheformatoftheiroutput.

12Someut
il
it
iesa
lsoha
vepa
rodi
es,s
eeddateorslf
ore
xampl
e.
Asme nt i
onedi nFi l
e sanddi rect
ories,therea respecialdir ectoriestoc onta
ine xecutablep r
ograms
andp r
ogr amswi thint hemc anber unb ytypingt hei
rna mea tthec omma nd-l
ine.Inge neralyouwi l
l
notha vepe rmis
siont opl acefil
e sint hesedirectori
esa nde x
pe ri
e ncedUni xusersc re
a t
et heirown,
normally~/bin/,t opl aceprogr a
mst heyus ef r
equently13
.Ifap rogrami snoti nas pecialdir
ectory,
youc annotr unitjus tb ytypingitsna me :thec omput erdoe sn'tk nowwhe retofindite venifthe
programi sinthec urrentdirectory
.Pr ogramswhi char enoti ns pec i
aldi
re c
tori
esc anstil
lber un,but
youha vetoi ncl
udet hepa tht owhe r
ei tcanbef ounda ndt hisc anbea ss impleas./program
(progr
a mi sincurre ntdi r
ectory)toamor ecompl exa bsolutepa tht osome whe rewhe r
es hared
programsa rekept( seefootnote13f o rahintofhowt oa l
leviatet histe
dium forc ommonl yus ed
programs)buty ouc ana l
way suset hec omma nd-l
ine'
sa ut ocompl eti
onfea t
ures,seetab-compl et
ion
below,tor educet hea mountoft y
pingne e
de d.
Onet hingyou'llquickl
ydiscoveristhatt hemous edoe snotmov ethec urs
o rint hetermi nal
.The
ter
mina li
nt e
rfa
cep re
da t
esthepopul ar
ityofmi ceb yde c
adesa ndal
ternati
v eme thodsofe ffici
ent
ly
movinga rounda nde diti
nghavebe ende veloped,keyboardshort-
cut
sbe ingdefinedf ormos tc ommon
operat
ions .Afewoft hesearelis
tedinTa ble3butp robablythemos tusefuli
st het abk e
yt o
completec omma ndna mesandpa t
hsint hefil
e s
ystem,referr
edtoa' tab-completion'.Pressingtab
oncewi l
lc omple
t eapa t
hupt ot hefir
sta mbiguityencounteredandp r
essi
nga ga ingivesal istof
poss
ibl
ec omplet
ions( youc a
nt ypethene x tle
tterors ooftheoney ouwa nta ndp r
esstaba gai
nto
att
emptf urt
hera uto-complet
ion).
Control-a Mov
etobe
ginni
ngofl
i
ne
Control-e Mov
etoe
ndofl
i
ne
Alt-f Mov
efor
war
donewor
d
Alt-b Mov
eba
ckwa
rdsonewor
d
Control-l Cl
ears
cre
en,l
eav
ingc
urr
entl
i
ne
Tab Tr
ytoa
utoma
tic
all
ycompl
etepa
th

Tab
le3:Commonk
eyb
indi
ngsf
ormov
ingar
oundc
ommand-
li
ne.

# Example of tab completion


# For the rest of this tutorial, we will assume the user is called ebi
whoami
ebi
pwd
/home/ebi
ls
Desktop Downloads Pictures Templates Videos
Documents examples.desktop Music Public Ubuntu One
# Change to a different directory don't press enter yet
cd D
# Pressing tab once has no effect since there are three possible options.
# Pressing tab again lists the three options, note thatcd D remains on the
# command-line for further editing.

13Creati
ngthedir
ectorydoesnotmakeits
peci
al.Therei
sav ari
able$PATHwhichi
salistofdir
ect
ori
esi
n
whichthecomputerlooksforp
rogr
amsandthec ommande xport PATH=~/bin:$PATHappendsthenew
dir
ector
ytothisli
st.Thi
sc ommandisof
tenaddedtothefil
e~ /.bashrcwhi
chisalis
tofc ommandstobe
runautomati
cal
lyeveryti
meane wtermi
nali
sope ne
d.
cd D<tab><tab>
Desktop/ Documents/ Downloads/
# Press e to disambiguate options, and tab again to complete.
cd De<tab>
# Gives
cd Desktop/
Ar ecor
di skeptoft hec ommandsy ouhav eentere
d,thehistoryc omma ndcanbeus edtoli
st
t
hems oy ouc anr ef
erba cktowha tyoudide ar
li
er.Thehistorycanalsobes ear
ched:Control
-rst
art
s
asearc
ha ndt hec omputerwi l
lmatcha ga
instyourhistor
ya syoutype;typi
nge nte
ra c
ceptsthe
cur
rentli
ne,typingCont rol-
ragai
ngoe stot henextma tcha ndControl-
gc a
ncelsthesea
rch.Hist
ory
canals
ober e f
erredt obye ntr
ynumbe r,l
is
tedus i
ngt hehistoryc omma nd:enter
ing!nont he
comma nd-l
i
newi llrepeathist
oryentr
yn,e nteri
ng! !wil
lrepeatthelastcomma nd.
Therearemany,oft
ent er
se,c omma ndsf
orma nipulati
ngfil
esandaf ewoft hemor
eusef
ulof
the
seareshowninTable4.Ma nyofthec omma ndsf orUnixhaveshortnames,oft
enonl
ytwoor
thr
eel
ette
rs,soerr
orstypi
ngc a neasi
l
yha veunintendeda ndseve
rec ons
equencesbeca
ref
ulwhat
youwri
tebecaus
eUnixr ar
elygivesyouas econdc hancetoc or
rectmista
kes.SomeUnixmachi
nes
havet
heslc omma ndtoe ncourageaccurat
et y
ping.
cd ChangeDir
ect
orychangethewor ki
ngdire
ctory
Exa
mpl e
s:
cd path # Change working directory to path
cd # Change to home directory
cd - # Change to previous directory
cp CoPyfil
ec opyafilefrom pl
acetoa nothe
r
Exampl
e s:
cp file1 file2 # copy file1 to file2
cp file1 directory/ # copy file1 into directory. The copy of the
file has path directory/file1
cp file1 file2 directory/ # copy file1 and file2 to directory. When
copying multiple files, the destination must be a path to a
directory.
ls Li
Stconte
ntsofdirec
tory
Exampl
es:
ls # List files
ls -a # Also show hidden files (those whose name begins with a
period).
ls -l # Show more information about each file (permissions, owner,
group, time and date of last modification).
mkdir MaKeDIRectoryc r
eateane wdirec
tory
Ex
amples
:
mkdir path # Make directory described by path
mkdir -p directory1/directory2# Make the directory described and
all directories leading to it (its Parents) if necessary.
mv MoVefil
emov e( r
ename)afile.Usageisexa ctl
yli
kec pe xce
ptt
hatt
hefil
eismov
ed
ra
thert
hanc opi
ed.
Exampl
es:
mv file1 file2 # Rename file1 to file2
mv file1 directory/ # Move file to directory
mv file1 file2 directory/ # Move files to directory
rm ReMovefil
er emov e(del
ete)afil
e.Ge neral
lydel
eti
ononUni xmachinesisperma nentand
i
nst
a nt
aneous;ther
eisnotrashdi rect
or ytos a
veyoufrom yourmi
sta k
es.
rm file # Remove file
rm directory # Fails, can't remove directories
rm -r directory # Recursively descend into directoryand delete
everything, including other directories inside of it (hence the
recursively). This will remove the directory
rm -f file # Force (ignore warnings) removal of file; ignoring
warnings includes read-only files.
rmdir ReMoveDIRector
yr emoveadi
rec
tor
y.Onl
yempt
ydi
rec
tor
iesc
anber
emov
ed(
thi
s
i
ncl
udeshi
ddenfil
es).
Exa
mple:
rmdir directory

Tab
le4:A f
ewc
ommandsf
ormani
pul
ati
ngfil
esandb
rie
fex
planat
ions
.
# Moving and copying
cd /home/ebi/examples/unix/MoveCopy
pwd
/home/ebi/examples/unix/MoveCopy
ls
alignmnet.fasta read-only test test2
mv alignmnet.fasta alignment.fasta
ls
alignment.fasta read-only test test2
cp alignment.fasta alignment_copy.fasta
ls
alignment.fasta alignment_copy.fasta read-only test test2
# Several files can be moved or copied if the destination is a directory
mkdir MyAlignments
mv alignment.fasta alignment_copy.fasta MyAlignments
ls MyAlignments
alignment.fasta alignment_copy.fasta

# Removing files and directories


pwd
/home/ebi/examples/unix/MoveCopy
# Some files are read-only (answer y)
rm read-only
rm: remove write-protected regular empty file `read-only'?y
# Some files are not yours
rm /dev/null
rm: remove write-protected regular file ` /dev/null'? y
rm: cannot remove `/dev/null': Permission denied
# rm will not delete directories
rm test
rm: cannot remove `test': Is a directory
# rmdir will only delete empty directories
rmdir test
rmdir: `test': Directory not empty
ls test
afile
rm test/afile
rmdir test
ls test2
afile subdirectory
# rm -r (-r = recursive) deletes everything, including subdirectories
# Danger a mistake using this option can result in a lot of work being
# accidentally deleted
rm -r test2
Therea
rema nycir
cums
tanc
eswhenitispr
efe
r abl
efors
ymbolsnottoha v
eas pe
cia
lmea ni
ng,the
mostcommonex a
mplebei
ngwhenthefil
enamec ontai
nsaspac
e .Thec
14
harac
teri
nquest
ionc a
nbe

esc
a pe
dbypr
efixi
ngitwi
tha'\'t
oremov ei
tsspeci
almeani
ngso,forex
a mple:/isther
oot

14As
pac
eisas
pec
ialc
har
act
eri
nthes
ens
etha
titi
sint
erp
ret
eda
sab
rea
kbe
twe
enc
omma
nd-
li
neopt
ions
.
di
rec
tor
ybut\/i
safil
eca
ll
ed'
/'.
# Escaping examples
pwd
/home/ebi/examples/unix/Escaping
ls
my sequences.fasta sequence_directory
# Incorrect version. Space in name treated as command-line argument separator.
# my and sequences.fasta treated as separate files.
mv my sequences.fasta sequence_directory
mv: cannot stat `my': No such file or directory
# The wrong file has been moved
ls sequence_directory
sequences.fasta
# Correct version, the space is escaped to remove its special meaning.
mv my\ sequences.fasta sequence_directory
ls sequence_directory
my sequences.fasta sequences.fasta
# If you use tab completion to complete names, spaces and other characters
# are automatically escaped for you.
File
sbe gi
nningwit
ha.c haracte
rarehiddenbydefaul
tandwillnotappeari
ntheoutputofl
sor
e
quivalent
.Ge nera
lhi
ddenfil
esarethos
eimpor t
antforthecomputerorprogra
ms,cont
aini
ng
c
onfigurat
ioninfor
mati
onnoti nt
endedfortheuser
.
pwd
/home/ebi
# Show ordinary files
ls
doc-samples examples
# Show all files. Note the special directories. and .. are visible.
ls -a
. .bash_history .bashrc .directory .mpd.conf examples
.. .bash_logout .config .kde4 .ssh
.Xauthority .bash_profile .dbus .local doc-samples
# Show only hidden files. For more details, seeDealing with multiple files
.
ls -d .*
. .Xauthority .bash_logout .bashrc .dbus .kde4 .mpd.conf
.. .bash_history .bash_profile .config .directory .local .ssh

Re
adi
nga
ndwr
it
ingpe
rmi
ssi
on
Allfil
esa nddi rectorie
sha veas etofpe rmissi
onsa ssociatedwi tht he m,de scri
bingwhoi sa l
lowe dto
readorwr i
teafil e.The r
ea rethre eba s
icpe r
mi s
sions:r eadr ,writew a nde xecutex.Theme anings
arefairlyobv i
ousot hertha nexecut e,whichha stwome aningsde pe ndingonc ontext:fornorma lfil
es,
executei sj
us tama rkertos howt ha tthefil
ec ontainse xecutablec ode( i
.e.i
sap rogram)bute xecute
permissionisa lsone ededtoope nadi rect
orya nds eet hefilesisc onta i
ns.The rea rethreecategor i
es
ofus er:owne ru,gr oupg,a ndot heroa ndt hepe rmissionsf oreac hfilea r
ede scri
be da sastri
ngof
ni
nec haracter
s ,thre efore achuse rcategory.Thet ripl
e tfore achc a t
e goryise i
theral ett
er'rwx'i f
usersint hatc ategor yha vethec orrespondi
ngpe rmi ssi
onor' 'i
- ft he ydon' t
.Thepe rmissi
ons tri
ng
rwxr-x---me anst ha ttheowne rha spe rmissi
ont or ead,wr it
eo re xe cute,usersint hes amegroup
haver eada nde x
ec utepe rmissi
ona ndotherus ersha venope rmissions .
# Which groups do I belong to?
pwd
/home/ebi
id
uid=521(ebi) gid=100(users) groups=6(disk),7(lp),11(floppy),
17(console),27(video),80(cdrw),100(users),521(ebi),1002(boinc)
,65533(nogroup),65534(nobody)
# User ebi has ID 521, in group users by default (Group ID 100). ebi is also a
# member of several other groups, giving access to features of the computer
# that would otherwise be denied.
# List some files and permissions. The initial 'd' means that bothdoc-samples
# and examples are directories. The owner of these files isebi and they are
# part of the users group.
mkdir test
ls -l
drwxr-xr-x 14 ebi users 352 Mar 22 14:02 doc-samples
drwxr-xr-x 3 ebi users 72 Mar 22 17:42 examples
drwxr-xr-x 2 ebi users 48 Mar 26 14:09 tests
# ebi has read, write and execute permission for both directories; users in the
# group users have read and execute permission, as do any other users.
# Remove execute permission for all users ( a means u, g and o)
chmod a-x test
# Now we can't open the directory.
cd test
-bash: cd: test: Permission denied
# Give ourselves permission to enter directory.
chmod u+x test
# This now succeeds but nobody else will be able to enter
cd test
# Make all files in and below a directory read-only. The-R flag means
# recursively descend into all directories inside test.
chmod -R a-w test
Astheowne rofafileyouc a
nc hangeit
spe r
missi
onstobea nythingandsomep rogra
msdot hi
sfor
youa utoma t
ica
ll
y,giv
ingtheimpressi
onthatthepermis
sionshavebe eni
gnored.Runningrm- fis
possi
blyt heonl
yt i
mey oumightrunintothisbehav
iour
:b ydefaul
trm willp
romptt oremovewr it
e-
prote
c t
e dfil
esbutthe-f(for
ce)fla
gt ur
nstell
sitnottobot he
ra s
kingandjustremov ethefil
e.

De
ali
ngwi
thmul
ti
pl
efil
es
Of t
en,e speciall
ywhe nrunnings cr
ipt
soror ganis
ingfil e
s,itisde s
ir
abl
etode a lwit
hmul t
iplefil
esa
t
onc e
.Ra t
he rtha ntypi
nge achfilenameoute x pl
ici
tl
y ,wec angivethecompute rapa tt
erninste
a dof
afilename :a l
lfile
name sarec hecke
da gai
nstthepa tte rnandi tisautomati
call
yr epl
acedbyal is
tof
ma tchi
ngfile sbe f
orerunningt hecomma nd.Pa tter
nsa rejustfil
enamescontai
nings ymbol
st hathave
as pecialme aning,forexampl e:*me ansma t
c ha nything,s oa*bi sapatter
nt ha tmatche
sa ny
fil
enamebe ginningwi t
haa nde ndi
ngwithbi nc l
udi
ngt hefileab.Ta bl
e5c ontainsalis
tofs peci
al
symbol susefulf orconstr
uctingpa t
terns
.
Sy
mbol De
scr
ipt
ion
* Ma
tcha
nyt
hing,i
ncl
udi
ngma
tch
not
hing
\* Ma
tcha'
*'c
har
act
er
? Ma
tcha
nyc
har
act
ere
xac
tlyonc
e(e
xcl
ude
sma
tchi
ng
not
hing
)
[abc] Ma
tche
xac
tlyoneof'
a','
b'or'
c'
[^abc] or [!abc] Ma
tcha
nyc
har
act
erbut'
a','
b'or'
c'
[c-y] Mat
cha nycha
rac
terbet
wee
n'c
'and'
y'.Not
e:[
-a]i
sde
fine
dtome
an
amatc
hwi t
h'-'or'
a'.
{pattern1,pattern2} Combinest
heres
ultofpatt
ern1a ndpat
ter
n2toge
ther
.Not
eifafil
eis
matc
he dbypa
tter
n1a ndpatt
ern2,iti
sret
urne
dtwic
e.

Tabl
e5:Spe
cials
ymbol
sforfil
enames.Aswitht
he\*exampl
einthet
abl
e,anyoft
hes
esy
mbol
s
canbepr
eve
ntedfr
om hav
ingas pe
cialmeani
ngby
esc
aping
the
m wit
ha'\'.
# Organise files by type. When moving or copying multiple files, the final
# argument must be a directory not a file.
pwd
/home/ebi/examples/unix/MultipleFiles
mkdir Fasta Tree Sequences
cp *.fasta Fasta
cp *.tree Tree
# Copy both Fasta and Fastq format files. Any other files with the suffix .fast?
# or .f? would also be matched, .fz for example which is occasionally used for
# compressed fasta files.
cp *.fast? *.f? Sequences
A more restrictive form, only matching fasta and fastq format
cp *.fast[aq] *.f[aq] Sequences
Asmenti
one
dabov e
,patte
rnma t
chi
ngoccur
sbefor
eacommandisrunandt
hepatt
ernisr
epl
ace
d
b
ynone,oneormorema tc
hes.Thecommandneve
rs e
est
hepat
ter
n,justt
here
sul
tsofthematc
h
a
ndthi
scanhaveuninte
ndedconse
quenc
es.
# Why we used the -d flag for ls in the previous section
pwd
/home/ebi
cd
# Now in home directory. The pattern is expanded to all files and directories
# matching, including the . and .. directories. When ls is run, it gets the
# directory names as arguments and so lists their contents.
ls .*
.Xauthority .bash_logout .bashrc .mpd.conf
.bash_history .bash_profile .directory

.:
doc-samples examples

..:
cilia ebi giorgos jon natassa pet spyros tkill
costas flx ioanna katerina nodas pierre tereza voula
elena gioannis jacques maria panagiotis pvavilis thanos
etc
# The -d flag for ls stops it from listing the contents of directories and
# instead just prints their names.
ls -d .*
. .Xauthority .bash_logout .bashrc .dbus .kde4 .mpd.conf
.. .bash_history .bash_profile .config .directory .local .ssh
Uni
ntendedcons
equenc
escanbedange
rous.Takes
peci
alca
rewhenus
ingpat
ter
nswi
th
c
omma nds.Thefol
lowi
ngexa
mpleisaj
okepla
yedonine
xpe
rie
nce
dUnixuse
rs.
This example can be dangerous BEWARE
pwd
/tmp
Create a file called -rf *
touch -- -rf\ \*
# Typing rm -rf * is a really bad idea. * matches everything, r means
# recursively descend down all directories matched, andf forces deletion even
# if the file is important or write-protected.
# Safely delete file. There are other ways.
rm -- '-rf *'
# The quote marks '-rf *' stop the filename being interpreted as a pattern. The
# -- prevents rm (and, more generally, most commands) from interpreting
# anything after it as a flag, so -rf is just a name not the recursive and force
# flags.

Runni
ngmul
ti
pl
epr
ogr
ams
From e arlyoni nitsde vel
opme nt,Uni xwa sde si
gnedt or unmul tipl
ep rogr
a mss i
mult aneouslyon
remot ema c hinesa nds uppor tf
ort hisi
si ntegratedintot hec omma nd-l
ine.Ani mportantdi st
inctionis
thatbe tweenf oregroundj obsandba ckgroundj obs:af oregroundjobt e mporarilyrepla
c esthe
comma nd-li
nea ndy ouc a nnotenterne wc omma ndsunt ilithasfinished,wher easaba ckgroundj ob
runsinde pende ntlya nda l
lowsy out ocont i
nuewi thot hert asks.Onl yfore
groundj obsre cei
vei nput
from thek ey board,s ointe r
acti
vep rogramsl ik
ePAUP*s houldber una sf
o r
egr ound( al
t houghy ou
coulds etupac omput eintensi
vea naly
s i
s,ba ckgroundi tandc ontinuewi thot hert as
kswhi l
eiti s
running.La te r
,whe nthec al
cul
a t
ionsha vefinished,thep rogramc anbema def oregrounda gainso
i
nt er
a ct
ionc a nc ontinue).Ba ckgroundj obss t
il
ls endthe i
rout putt ostdout,y ourt er
mi nalunle s
sy ou
ha v
er edire
c tedi tsome whe reelse,whichc anbec onfusingi fyoua rerunningmul t
ipleba ckgroundj obs
t heiroutputwi llbeinte rl
eave
dwi t
houta nyi ndicati
onofwhi chlinec amef rom whi chj ob.
Control-c Ca
nce
l(k
il
l)f
ore
groundj
ob
Control-z Pa
usef
ore
groundj
ob
jobs Li
stc
urr
entj
obs(
sta
rte
dint
hisc
omma
nd-
li
ne)
kill %n Ki
l
ljobnumbe
rn
killall name Ki
l
lal
lpr
oce
sse
sca
ll
edname
ps Showallr
unni
ngp
roc
ess
es(
dis
tinc
tfr
om j
obs
)re
gar
dle
ssofhowt
hey
weres
tart
ed
fg %n Br
ingj
obnumbe
rnt
ofor
egr
ound
bg %n Runj
obnumbe
rni
nba
ckgr
ound
program & St
artprogrami
nba
ckgr
ound
nohup program Runprograminbac
kgroundsoitwil
lnotst
opi
fyoulogout
.stdout
andstderrarer
edi
rec
tedt ot
hefil
enohup.
out
.Adva
nceduser
smight
l
iket
ol ooka
tscreeninste
ad.

Tab
le6:A f
ewc
ommandsandk
eyc
omb
inat
ionsf
orj
obc
ont
rol
.

Ashinte di nTable6,t hereisadi ffe


r encebe t
weenaj oba ndap r
oc ess.Ap rocessisas i
ngle
programr unni ngont hema chi
ne ,e achofwhi chisunique l
ynumbe red(api d,Pr ocessID) .Youc anl i
st
al
lt heproc essesyoua rerunning,i ncludingt hecomma nd-li
neitsef,us
l15
ingps( orps- ai fy ouwa ntto
seewha ta lltheot herus ersoft hema chinea r
edoing).Thec omma nd-li
nei t
selfisjusta nother
processrunni ngont hec omput er,a l
be i
tones peci
all
yde signedfors tart
ing,stoppinga ndma ni
pulat
ing
otherp r
oce sses.Proc essesaret hef unda me ntalmethodofk eepingt ra
ckofwha tisrunningont he
comput er
.J obs,ont heotherha nd,a ret hi
ngse nte
redont hec omma nd-li
nea ndma nyinc l
udes ever
al
programsl ogicall
yc onne ctedtoge the rb ypipes(seeIn,outa ndpipe sforde t
a i
ls)toa chieveat ask.
Thec omma nd-l
ines pli
tsthej obsi ntos ev e
ralproces
se sa ndrunst hem,pos sibl
ys i
mul taneous l
y.
# Time a cup of tea. Computer sleeps for 300 seconds and then prints Tea
# brewed.
sleep 300; echo 'Tea brewed!'
Tea brewed!
# Backgrounding does not have the effect you might think. The following
# backgrounds the echo but not the sleep; backgrounding the sleep would have
# the effect of immediately running both the programs. Similarly, interrupting
# the sleep with Control-z will immediately allowecho to run.
sleep 300; echo 'Tea brewed!' &
# Correct method of backgrounding: group programs using brackets and background
# entire group. The space between the bracket and the command is important.
{ sleep 300; echo 'Tea brewed!'; }&

I
n,outa
ndpi
pes
Wherepossi
bl
e,Uni xc omma ndsa rewrit
tenasfilt
ers:theyreadf r
om input,ma ni
pula
tetheda t
a
andwri
tetheoutput.Thi smights oundt r
ivi
al
,tautol
ogouse ven,butitena bl
essimplecomma ndsto
becombi
nedtop roducec omplexre s
ults.Ever
ycomma ndr e
adsfrom stdina ndwr i
testostdout,by
def
aul
tstdoutisc onnectedtot hec urr
entcomma nd-li
ne,sor es
ultsaredispl
ayedont hescre
en,but
i
tcanberedir
ected:> filenamer e
directsstdouttot hefil
es pec
ifie
dforlaterperusal
.Ra t
herthan

15Ge
ner
all
yca
ll
edbash,t
heBour
neAga
inSHe
ll
,apunont
heor
igi
nalUni
xshe
llwr
it
tenb
ySt
ephe
nBour
ne.
r
edi
rec
tingtoafil
e,apipecanbeusedtoconnectstdoutofonecommandtot
hestdinofanot
her
bychaini
ngmanysimplec
omma ndstoge
ther,c
omplextra
nsfor
mati
onsoft
hei
nputcanbea
c hi
eve
d.
Foll
owingi sanadvanc
ede x
ampl e,showinghowacomplexoutputca
nbea chie
vedusingaser
iesof
s
ma ll
erst
e ps.Youdon'tknowsuffic
ientyettounde
rst
ande v
ery
thingi
nt hi
sexamplebuttryt
owor k
t
hroughita nds eewha
te achst
epi sdoing.Themanpa ge
sforeachcomma nd(seeGetti
nghel
p)
mightbeus eful
.
# An advanced example using pipes. At the command-line, a pipe is represented
# by the character |.
pwd
/home/ebi/examples/unix/Pipes
# The compressed file transcripts.fasta.gz contains the fasta
# sequences of all transcripts of Homo sapiens chromosome 22
# (from Ensembl release 57). Want to count how many transcripts
# there are for each gene.
# First cat reads the file and writes it to stdout, pipe into the
# decompression program gunzip
cat transcripts.fasta.gz | gunzip |
# Another pipe into grep, a tool that extracts lines matching a
# certain pattern (here, those starting with a >). The pattern to
# match is described using a Regular Expression a very important
# concept than underlies many Unix tools but too advanced for this
# tutorial.
grep '^>' |
# The sequence names in the fasta file are of the form
# >GENE_ID|TRANSCRIPT_ID
# cut splits a line to bits. Use | as the delimiter and we want
# the first field. The single quotes prevent the '|' being
# interpreted as a pipe by the command-line.
cut -d '|' -f 1 |
# Sort and count the unique entries (uniq requires sorted input)
# Output to file transcript_counts.txt
sort | uniq -c > transcript_counts.txt
# Or on one line, redirecting stdin in a similar way to how we redirected
# stdout before. The < transcripts.fasta.gz connects the stdin of gunzip to the
# file transcripts.fasta.gz rather than using cat to read it and output it into
# a pipe.
cat transcripts.fasta.gz | gunzip | grep '^>' | cut -d '|' -f 1 |
sort | uniq -c > transcript_counts.txt

Comp
res
sion
Theaim ofcomp res
sionistoma kefile
ss ma l
l
er,usef
ulforbot hsavi
ngdis
ks paceandma kingit
qui
ckert
os endfil
esovert hei
nter
net Si
16
mply,comp r
essi
onp rogramslookforfr
equentl
yrepeated
pat
ter
nsinthefileandre movethi
sre dundancyinama nnerthatc anbeundonelater
.Textfil
e st
end
tocompres
sv er
ywe l
l,100MBwor t
hofWi kipedi
abe i
ngc omp re
ssedintol
essthan16MB17,a nd,i
n

16Somet ypesofconnecti
onov erthei
nter
nethavetheabil
i
tytotr
a nspar
ent l
ycompre
s sfil
esbef
oresendi
ng
anduncomp re
ssa ttheotherend.Somewe bser
versi
mplementthisbutt heonl
yimport ante
xampleforusi
s
scp/sftpwhi c
hc anbegi ve
nt he-Copti
ontorequestcompr
ession.E.g.scp -C sequences.txt
auser@anothermachine.org:/home/ebi/
17SeeTheHut terprieht
z tp://pri
ze.
hutt
er1.
net
/
part
icul
a r
,biol
ogi
cals
equence
st e
ndt obeveryc
ompr
ess
ibl
esi
ncethesiz
eoftheal
phabetof
nucl
eotidesoraminoaci
dsissmallcompar
edtothet
ota
lcompute
ralphabe
tofal
llower
-cas
eand
upper-c
a s
ec ha
ract
ers
,numbers,symbol
s,etc
.
The rearet woc ommont oolsforcomp ress
ingfil
es:gzipa ndbzip2wi tht he i
rre s
pec ti
vetoolsfor
unc omp r
essing:gunzipa ndbunzip2.gzipi sthede -
factos t
anda r
d;bzip2t endst op roducesma ll
er
fil
esbutt ak eslongertoc omp r
essthem.Ont heWi ndowspl atform,theZip c
18
omp res
sionme thodi s
favoureda ndma nyUni xplatf
ormsp rov i
dezipa ndunzipt oolstodealwitht hesefil
e s
.Non- Linux
Unixpl atf
or ms,Ma cOs Xf orexample ,haveoldertool
sc all
edcompressa nduncompresst hata r
e
rarelyuseda nymo r
e .Supportforcompress' dfil
esonLi nuxc anbepa tchy
,f ore x
a mple:ama chineI
havea ccesst oha sacompressma nua lpagebutnoa c
tuallytoolinst
all
ed.Afina lme thodt obea wa r
e
of,t hatisbe comingmor epopul a
r,is7- zi
p(7za)whi chc anproduc esmall
erfile sthana lltheabove
me thods,a gaina tthee x
penseoft akinglongertoc ompress.Al is
toffil
es ufficestha tca nbeus edto
i
de ntif
ywha tfil
esarec ompressedusingwha tme thodisp rovi
de dinTable7.
pwd
/home/ebi/examples/unix/Compression
ls
sequences.fq
# Gzip'ing a file
gzip sequences.fq
ls
sequences.fq.gz
# Unzipping the file
gunzip sequences.fq.gz
ls
sequences.fq
# Using bzip2
bzip2 sequences.fq
ls
sequences.fq.bz2
# As part of a pipe, reading from stdin and writing to stdout
cat sequences.fq.bz2 | bunzip2 | gzip > sequences.fq.gz
ls
sequences.fq.bz2 sequences.fq.gz
Comp ress
ionwor ksbett
e riffil
e sarec ombineda ndt henc ompress
e dtogether
,ra t
hert han
compress
ingthemi ndivi
duall
y,sinc ethisa l
lowst hecomp ress
ionp r
ogramt os potrepeate
dpa tter
ns
bet
we e
nt hefil
es.OnUni x,thep roce
s sofpa c
king/unpa c
kings e
veralfil
esint
o/f rom as ingl
efil
ehas
beenhis
tori
call
ys e
pa ra
tefrom t hep r
oc essoft hec ompressi
on,ink eepingwiththephilosophyof
havi
nglit
tletool
st hatdoonet hingwe ll.TheUni xtoolforpa ck
inga ndunpa cki
ngfil
esistar Tape
Archi
ver
,theoddna mebe causei tsheritagegoe sbackt o1979whe nwr it
ingfil
estoma gne ti
ctape
wasac ommonme t hodofstorage .
ls
chimp.fasta human.fasta macaque.fasta orangutan.fasta
# Pack into single file. The suffix is your responsibility. '
c' means create, and
# 'f' means that the next argument is the filename to write to.
tar -cf sequences.tar *.fasta
# Note that the original files are untouched

18Popul
ari
seda
ndoft
enknownasWinzi
p(ht
tp:
//www.wi
nzi
p.c
om/)butor
igi
nal
l
yinv
ent
edb
yPhi
lKa
tza
s
pkzipandnowha
ndle
dautomat
ica
ll
ybyWindowsandMacOs X.
ls
chimp.fasta human.fasta macaque.fasta orangutan.fasta sequences.tar
# Delete all sequences
rm *.fasta
# 'x' means extract
tar -xf sequences.tar
ls
chimp.fasta human.fasta macaque.fasta orangutan.fasta sequences.tar
Ov
erti
me,thef
eatur
esoftarhaveinc
r e
asedt
oma
kei
tmor
econv
eni
enta
ndmode
rnv
ers
ionsa
re
nowc
apa
bleofpac
kingandcompre
ssingfil
es.
ls
chimp.fasta human.fasta macaque.fasta orangutan.fasta sequences.tar
# Pack and gzip sequences simultaneously
tar -zcf sequences.tgz *.fasta
# List the contents without extracting
tar -ztf sequences.tgz
chimp.fasta
human.fasta
macaque.fasta
orangutan.fasta
# More recent versions of tar can also bzip2 files
tar -jcf sequences.tbz2 *.fasta
tar -jtf sequences.tbz2
chimp.fasta
human.fasta
macaque.fasta
orangutan.fasta
Comp
res
sion Unc
omp
res
sion19 Suffix Ta
r'dSuffix
gzip gunzip .gz .tgz
bzip2 bunzip2 .bz2 .tbz2
compress uncompress .Z Noc
onv
ent
ion,.
tar
.Z
zip unzip .zip Notne
ede
d
7za 7za e archive.7z .7z Notne
ede
d

Tab le7:Fi l
esufficesforcommonc ompressi onprograms.Whenc ombinedwithtartoc ompre s
s
mul ti
plefil
es,of
te nt hefulls
uffix.tar.suffixisshortene
dt ot
hatgiv
enab ove.zipand7za 7-z
ip
hav eaWi ndowshe r
itageandhav ebuil
tme tho
dstoc ombinemult
ipl
efile
st o
gethe
r,soar erarel
y
us edinconjunctionwi t
htar.Thefilet oolc analsobeus e
dtodeter
mi nefil
etype,e
.g:file
file.unknown.suffix.Se eman filef
orde t
ail s.

Wo
rki
ngonr
emot
ecomput
ers
Whyus
ear
emot
ecomput
er?The
rea
rema
nyr
eas
ons
:Fi
rs
tly
,ce
ntr
alc
omput
ingr
esour
cest
endt
o

19Thec ompress
ionp
r ogr
amsa ct
ualdobot
hcompr
ess
iona
nddecompr
ess
ion.Thesena
mesareconv
enie
nce
sy
nony msforthecomp r
ess
ionprogr
amandwha
teve
rcommand-l
i
neopt
ionsitr
equi
rest
ofli
piti
nto
decompres
sionmode .

You might also like