This preview shows page 1. Sign up to view the full content.
Unformatted text preview: story, and the left/right arrow k ey s to move y our c urs or and modify the
c ommand before res ubmitting it for ex ec ution. This tric k bec omes us eful when y ou want to run a s eries of s imilar c ommands , lik e in
the following s ec tion. ls
Suppos e we want to k now the c ontents of a direc tory . The ls program (s hort for "lis t direc tory c ontents ") is des igned to do ex ac tly
that. It c an tak e z ero or more arguments : l [ietr]..
s drcoy .
If run with no arguments , it jus t lis ts the c ontents of the c urrent work ing direc tory :
kcmb@iu3 ] s
If run with arguments , it interprets the arguments as direc tories and lis ts the c ontents of thos e direc tories .
[aap2lnx ~$l pr1
kcmb@iu3 ] s at
The direc tory argument is ac tually a pa th. W ith no leading "/" c harac ter it is a re la tive pa th, meaning that it is followed relative to
the c urrent work ing direc tory . W e c an als o us e abs olute paths :
In eac h direc tory , there are als o s ome s pec ial direc tories to help y ou navigate the files y s tem, but they are hidden by default (on the
GUI as well as the CLI). To s how them, we run ls with "-a" as an argument:
Single c harac ter arguments prec eded by a "-" c harac ter are c alled fla gs. They are us ed to modify the behavior of a program. In this
c as e, the "-a" flag tells ls to s how hidden files and direc tories . In Unix , thes e are any files or direc tories that s tart with a "."
c harac ter. You will s ee output lik e the following:
W e're interes ted in the firs t two entries , the res t are hidden c onfiguration files us ed by programs running on the s y s tem. The firs t
direc tory is c alled "." It alway s c irc ularly referenc es the direc tory that it's in. This may s eem s trange, but it c an be us eful. For
ex ample, if ls didn't work without any arguments , we c ould s till lis t the c ontents of the c urrent work ing direc tory with:
The s ec ond entry is "..", whic h is a referenc e to the pa re nt dire ctory. This is the direc tory whic h c ontains the direc tory that it's in.
W e us e this entry to navigate down the files y s tem tree toward the root. Let's s ee what happens when we pas s it as an argument to
[aap2lnx ~$l .
kcmb@iu3 ] s .
alnu brkt ca1
oix2 aaa2 he4
alws bmoe ceg8
abl hag6 kcmb mto1 odn1
un16 aap2 irs
kros mrwr pr39
ukw1 toe2 ak7 teen wn49
hne3 fgn This look s lik e a lis t of other people's home direc tories , whic h mak es s ens e s inc e we were in /home/k ac ampb2 s o the parent
direc tory is /home. Mak e s ens e?
Let's play with s ome fanc ier paths . Try the following with ls :
s //at//.../. Can y ou ex plain how eac h path is evaluated? Be s ure to as k for help if y ou don't unders tand.
It's helpful to us e ls often. It's alway s good to verify the c ontents of y our c urrent work ing direc tory . cd
If we want to go to another direc tory , we us e the cd program, s hort for "Change work ing direc tory ". The s y ntax of c d is s imply :
For ex ample, to go into the part1 direc tory and lis t the c ontents , we c an do:
Now what happens wh...
View Full Document
- Fall '14