You are on page 1of 26

1

!"#$%# %#%'()*+

Paits of this tutoiial has been auapteu fiom N. Stonebank's !"#$ &'()*+,- .)*
/01+220*3 4http:www.ee.suiiey.ac.ukTeaching0nix).
1 Insta|||ng Ubuntu
About Ubuntu

Foi oui lab sessions we aie going to use the opeiating system 0buntu. 0buntu is
an opeiating system, just like Winuows XP, Winuows vista, Winuows 7, anu Nac
0S X aie opeiating systems. The main uiffeience between 0buntu anu these
othei opeiating systems is that it is fiee anu open-souice. 0pen-souice means
that is has been cieateu by a collective of thousanus of volunteeis anu that the
souice coue is fieely available anu constantly being impioveu upon anu
examineu foi bugs.

The ieason we will use 0buntu insteau of Winuows is that much of the scientific
softwaie useu foi the applications uesciibeu in oui couise, has been uevelopeu
on Linux-baseu opeiating systems such as 0buntu. In auuition, 0buntu is one of
the most usei-fiienuly Linux-baseu opeiating systems aiounu, making it the
optimal choice foi oui lab sessions. Note that it shoulu theoietically be possible
to iun most of the softwaie we aie going to use unuei Winuows, but this woulu
iequiie a lot of tinkeiing to get it to woik. You aie most welcome to tiy if you
know youi way aiounu a computei, but we will not pioviue any suppoit foi
iunning the softwaie on Winuows.

Anothei gieat thing about 0buntu is that it is possible to install it on a 0SB flash
uiive anu then stait up fiom that flash uiive. That means that we uo not have to
install an entiiely new opeiating system on a computei, but we can insteau caiiy
aiounu 0buntu in oui pocket, iunning it on almost any Winuows machine you
come acioss. Aftei you have useu 0buntu, you can simply iestait youi machine,
take out the 0SB key anu stait up youi oiiginal Winuows again, without any
pioblems.

Insta|||ng Ubuntu on a US8 f|ash dr|ve

What we'ie about to uo will ,(*-, *++ %., /*%* on youi 0SB flash uiive, so make
suie you have backeu up any impoitant infoimation you might have saveu on it!
The fiist step will be to foimat the 4+uB 0SB flash uiive. uo into the 5+26)73
89:-)*0* oi &;+3 <)=:'(0*, iight-click on the 0SB uiive's icon, anu select >)*=,(.

2

>)*=,((+21 , !?/ 6*+@0

0sually the uefault settings aie fine the way they aie; just make suie you foimat
it as 01234.

















>)*=,( 30((+213

Then click stait anu wait foi the foimatting piocess to finish. Now we aie almost
ieauy to put 0buntu on it. Fiist, we neeu to uownloau two files. Stait by
uownloauing the S2-bit Besktop Euition of 0buntu (Luciu Lynx LTS 1u.u4.1, 56
S
78$%,+ 9:;< /,-=%'> 6?) fiom http:ieleases.ubuntu.comluciu. This is a laige
uownloau (~9uuNB). Then uownloau @)$#9 !AB @)C, 6(,*%'( fiom
http:www.linuxliveusb.com. What you've just uownloaueu is a self-extiacting
aichive. Run it anu it will ask you foi a location to extiact the actual piogiam to.
Pick the Besktop ('Skiiveboiu'). Then iun the piogiam insiue the new foluei that
was cieateu on youi uesktop. If you aie not sitting in the 0penLab, you will neeu
special login cieuentials to be alloweu to iun the piogiam. Ask us about this anu
use it to execute the piogiam. Wait until the 0buntu uownloau is uone befoie
you continue. Now we'ie ieauy to put 0buntu on the 0SB stick. Fiie up @)$#9
!AB @)C, 6(,*%'(, which shoulu look like this:





































A+2'9 A+@0 !?/ <*0,()* ,( 3(,*(B':

4
Select youi 0SB stick fiom the uiopuown list in step 1. In step 2, click on
8ADE8FGEH85 anu select the 0buntu IS0 image file you just uownloaueu. The
piogiam will then stait checking the IS0 image anu when it's uone it shoulu look
like:





?(0: CD ?0-0E(+21 ,26 E;0EF+21 (;0 #?G +=,10

Because we woulu like to save oui changes eveiy time we iestait 0buntu, we aie
going to make the installation on the 0SB stick :0*3+3(02(. Step S is wheie we tell
the piogiam how much space we woulu like to have to save files in, install
piogiams, etc. Because of technical uetails
1
, the maximum size is 4 uB.
Somewheie between S anu 4 uB will be fine. In the example below, it's been set
to S uB. Be waineu, the laigei the you make the file, the longei the final
installation will take.






?(0: HD ?:0E+.I+21 (;0 3+J0 ). (;0 :0*3+3(02E0 .+-0

The uefault settings foi step 4 tenu to be fine, so skip to step S anu click on the
lightning bolt to stait installing 0buntu on youi 0SB stick! This will take at least
1S-2u minutes.





?(0: KL 7;02 0@0*I(;+21 ;,3 1)20 *+1;(M

When it's uone, we'ie going to ieboot the machine anu stait up 0buntu. Bo not
eject the 0SB flash uiive anu keep it in the 0SB slot. We now neeu to tell the PC
iight aftei we iestait it that it neeus to boot fiom the 0SB flash uiive (0buntu)
insteau of fiom the haiu uisk (Winuows). We uo this by enteiing the B''% F,$#,
anu this is usually uone by piessing one of the function keys iight when the
computei is staiting up (so N0.)*0 you see any sign of Winuows being staiteu!)
At RSLIS, you usually have to piess F9 to entei the B''% F,$#, but it might be a
uiffeient function key on uiffeient machine (such as F12 oi F2). Youi computei
will always show on the scieen which key you neeu to piess, but you will neeu to
be fast. 0sually you will only have S-S seconus to piess it.


1
The laigest file size FATS2 will allow is 4uB.
S
Restait the PC anu entei the boot menu. Select booting fiom 0SB stick anu wait
as 0buntu is staiteu up. This might take a few minutes. When you'ie askeu foi
anothei choice between (among othei things) 5,(-)-%,$% F'/,, @)C, F'/,, anu
8$-%*++. Select the top option (5,(-)-%,$% F'/,). Nevei select 8$-%*++ oi 0buntu
will stait installing itself peimanently on youi machine, oveiwiiting the cuiient
Winuows installation! Nothing scaiy will happen to youi machine if you choose
@)C, F'/,; any changes you make in 0buntu will just not be saveu.

Congiatulations! If all went well, then you've just staiteu 0buntu foi the fiist
time!
2 Lxp|or|ng Ubuntu

Below you see a pictuie of what youi uesktop will look like the fiist time you
stait up 0buntu.








Let's look at the thiee menus at the top iight: 1>>+)I*%)'$-, 5+*I,-, anu AJ-%,K.
1>>+)I*%)'$- is wheie you can finu many of the applications in 0buntu (at least
This is wheie you log
out, iestait oi shut
uown youi computei
0ne way of ueleting files )$-)/,
the usei inteiface (= Teiminal)
is uiagging them to the tiash
heie.
Click on this icon to
tempoiaiily hiue all the open
winuows on youi uesktop
This is wheie you stait up
piogiams, open Exploiei-type
winuows, oi altei settings
6
the ones with a u0I!). This woiks just like the A%*(% menu in Winuows.





















&;0 O::-+E,(+)23 =02' +2 !N'2('

0nuei O::-+E,(+)23 > OEE033)*+03 you can finu some useful applications, such as
the stanuaiu text euitoi L,/)% 2,9% M/)%'( foi instance, the 0buntu equivalent of
Winuows' N'%,>*/. The 5+*I,- menu lists uiffeient common oi impoitant
locations on youi computei.






















&;0 P-,E03 =02' +2 !N'2('
7
If you select youi P-,E03 > Q)=0 >)-60*, you open a file exploiei winuow of youi
home uiiectoiy. Youi home uiiectoiy is wheie youi peisonal files anu
subuiiectoiies aie saveu. The winuow shoulu look something like this (minus
the !6O0*++4PQP foluei, which we'll cieate latei)

















R)'* ;)=0 .)-60* +2 !N'2('

The thiiu menu that is inteiesting is the AJ-%,K menu. This is wheie you can
altei many of 0buntu's settings, such as usei accounts, uesktop backgiounus,
keyboaiu layouts, install new softwaie, etc.





















&;0 ?I3(0= =02' +2 !N'2('
8
Tiy it out by upuating the time by going to ?I3(0= > O6=+2+3(*,(+)2 > &+=0 ,26
S,(0.

You can cieate shoitcuts to each of the items in these thiee menus on, foi
instance, youi uesktop. }ust uiag an icon to the uesktop. Tiy uiagging the Fiiefox
biowsei icon to youi uesktop. If all went well, you now have a link to Fiiefox on
youi uesktop as well. Tiy playing aiounu with 0buntu a bit to get a feel foi how
things woik.

When you'ie ieauy, we'ie going to uig a little ueepei into 0buntu. uo to
O::-+E,(+)23 T OEE033)*+03 anu stait up a 2,(K)$*+. This shoulu look like this


&0*=+2,- B O .*03;-I ):0206 &0*=+2,- 7+26)7

The 2,(K)$*+ is similai to the 6'KK*$/ 5('K>% in Winuows. It's a commanu-
line inteiface to the system. This means that you can get uiiect access to all the
functionality by typing in commanus. In some cases, using a u0I is supeiioi, but
foi othei tasks being able to uiiectly execute multiple tasks with a single line of
commanus can save you lots of time. It uepenus on the task youi peifoiming
whethei one oi the othei is the best choice. In the iest of this tutoiial you'll leain
to use the commanu line foi small tasks.
3 L|st|ng f||es and d|rector|es
|s (||st)

When you fiist open a Teiminal winuow, youi cuiient woiking uiiectoiy is
(neaily) always youi home uiiectoiy. As mentioneu befoie, youi home uiiectoiy
is wheie youi peisonal files anu subuiiectoiies aie saveu. Youi home uiiectoiy
9
noimally has the same name as youi usei-name; in oui case it will always be
!"!#$!, since we'ie booting a special veision of 0buntu uiiectly fiom the 0SB
stick.

To finu out what is in youi home uiiectoiy, type

%&
N0TE: eveiy commanuline in these blackyellow boxes neeus to be followeu by a |Retuinj

The %& commanu (loweicase L anu loweicase S) lists the contents of youi
cuiient woiking uiiectoiy.


&0*=+2,- B *'22+21 (;0 %& E)==,26

Theie may be no files visible in youi home uiiectoiy, in which case, the 0NIX
piompt will be ietuineu. Alteinatively, theie may alieauy be some files inseiteu
by the System Auministiatoi when youi account was cieateu.

%& uoes not, in fact, cause all the files in youi home uiiectoiy to be listeu, but only
those ones whose name uoes not begin with a uot (() Files beginning with a uot
(() aie known as hiuuen files anu usually contain impoitant piogiam
configuiation infoimation. They aie hiuuen because you shoulu not change them
unless you aie veiy familiai with 0buntu anu Linux.

To list all files in youi home uiiectoiy incluuing those whose names begin with a
uot, type

%& )*
1u

As you can see, %& )* lists files that aie noimally hiuuen.


&0*=+2,- B *'22+21 (;0 %& )* E)==,26

%& is an example of a commanu which can take options: )* is an example of an
option. The options change the behavioi of the commanu. Theie aie manual
pages that tell you which options a paiticulai commanu can take, anu how each
option mouifies the behavioi of the commanu. We'll get to this latei in this
tutoiial.
4 Mak|ng d|rector|es
mkd|r (make d|rectory)

We will now make a subuiiectoiy in youi home uiiectoiy to holu the files you
will be cieating anu using in the couise of this tutoiial. To make a subuiiectoiy
calleu +,-.*%%/010 in youi cuiient woiking uiiectoiy type

23456 +,-.*%%/010

You aie moie than welcome to choose a uiffeient name foi this uiiectoiy, but
this is the name we'll be using in the iest of this tutoiial anu in all othei tutoiials.
To see the uiiectoiy you have just cieateu, type

%&
11
S Chang|ng to a d|fferent d|rectory
cd (change d|rectory)

The commanu 74 uiiectoiy means change the cuiient woiking uiiectoiy to
'uiiectoiy'. The cuiient woiking uiiectoiy may be thought of as the uiiectoiy you
aie in, i.e. youi cuiient position in the file-system tiee.

To change to the uiiectoiy you have just maue, type

74 +,-.*%%/010

Type %& to see the contents (which shoulu be empty)

Lxerc|se 1

Nake anothei uiiectoiy insiue the +,-.*%%/010 uiiectoiy calleu "*73!8&
6 1he d|rector|es . and ..

Still in the +,-.*%%/010 uiiectoiy, type

%& )*

As you can see, in the +,-.*%%/010 uiiectoiy (anu in all othei uiiectoiies), theie
aie two special uiiectoiies calleu (() anu ((()

1he current d|rectory (.)

In 0NIX, (() means the cuiient uiiectoiy, so typing

74 (
N0TE: theie is a space between 74 anu the uot

means stay wheie you aie (the +,-.*%%/010 uiiectoiy).


This may not seem veiy useful at fiist, but using (() as the name of the cuiient
uiiectoiy will save a lot of typing, as we shall see latei in the tutoiial.

1he parent d|rectory (..)

((() means the paient of the cuiient uiiectoiy, so typing
12

74 ((

will take you one uiiectoiy up the hieiaichy (back to youi home uiiectoiy). Tiy
it now.

Note: typing 74 with no aigument always ietuins you to youi home uiiectoiy.
This is veiy useful if you aie lost in the file system!
7 athnames
pwd (pr|nt work|ng d|rectory)

Pathnames enable you to woik out wheie you aie in ielation to the whole file-
system. Foi example, to finu out the absolute pathname of youi home-uiiectoiy,
type 74 to get back to youi home-uiiectoiy anu then type

894

The full pathname will look something like this

:;<2=:!"!#$!

which means that !"!#$! (youi home uiiectoiy) is in the ;<2= sub-uiiectoiy,
which is in the top-level ioot uiiectoiy calleu ":". Below is a visualization of the
uiiectoiy tiee stiuctuie anu the location of youi home uiiectoiy.









?=,-- :,*( ). (;0 (*00 3(*'E('*0 ). (;0 '260*-I+21 6+*0E()*+03

0se the commanus 74, %& anu 894 to exploie the file system. Remembei, if you
get lost, type 74 by itself to ietuin to youi home-uiiectoiy.
8 More about home d|rector|es and pathnames
Understand|ng pathnames

Fiist type 74 to get back to youi home-uiiectoiy, then type
home
/ (root)
usr etc
ubuntu
1S

%& +,-.*%%/010

to list the contents of youi +,-.*%%/010 uiiectoiy.

Now type

%& "*73!8&

You will get a message like this

%&> 7*##<$ *77=&& "*73!8&> ?< &!7; @5%= <6 456=7$<6A

The ieason is, "*73!8& is not in youi cuiient woiking uiiectoiy. To use a
commanu on a file (oi uiiectoiy) not in the cuiient woiking uiiectoiy (the
uiiectoiy you aie cuiiently in), you must eithei 74 to the coiiect uiiectoiy, oi
specify its full pathname. To list the contents of youi "*73!8& uiiectoiy, you must
type

%& +,-.*%%/010:"*73!8&

~ (your home d|rectory)

Bome uiiectoiies can also be iefeiieu to by the tilue B chaiactei. It can be useu
to specify paths staiting at youi home uiiectoiy. So typing

%& B:+,-.*%%/010

will list the contents of youi +,-.*%%/010 uiiectoiy, no mattei wheie you
cuiiently aie in the file system.

Lxerc|se 2

What uo you think

%& B

woulu list.

What uo you think

%& B:((
14

woulu list.
9 Copy|ng I||es
cp (copy)

78 @5%=1 @5%=/ is the commanu, which makes a copy of @5%=1 in the cuiient
woiking uiiectoiy anu calls it @5%=/.

What we aie going to uo now, is to take a file that we uownloau anu save in the
C<9#%<*4& uiiectoiy, anu use the 78 commanu to copy it to youi +,-.*%%/010
uiiectoiy. 0pen Fiiefox (if it isn't still open in the backgiounu) anu go to this
0RL: http:www.ee.suiiey.ac.ukTeaching0nixscience.txt. In Fiiefox select
'Save Page As' anu save it in the C<9#%<*4& uiiectoiy. This shoulu be the uefault
uiiectoiy Fiiefox offeis to save it in.

Now we'ie ieauy to copy this file to anothei location. Fiist, 74 to the
+,-.*%%/010 uiiectoiy.

74 B:+,-.*%%/010

Then at the 0NIX piompt, type,

78 B:C<9#%<*4&:&75=#7=($D$ (
Note: Bon't foiget the uot ( at the enu. Remembei, in 0NIX, the uot means the cuiient uiiectoiy.

The above commanu means copy the file &75=#7=($D$ fiom the C<9#%<*4&
uiiectoiy to the cuiient uiiectoiy, keeping the name the same.

Lxerc|se 3

Cieate a backup of youi &75=#7=($D$ file by copying it to a file calleu
&75=#7=("*3.
10 Mov|ng f||es
mv (move)

2E @5%=1 @5%=/ moves (oi ienames) @5%=1 to @5%=/.

To move a file fiom one place to anothei, use the 2E commanu. This has the effect
of moving iathei than copying the file, so you enu up with only one file iathei
than two.

1S
It can also be useu to iename a file, by moving the file to the same uiiectoiy, but
giving it a uiffeient name.

We aie now going to move the file &75=#7=("*3 to youi "*73!8& uiiectoiy.

Nake suie you aie insiue youi +,-.*%%/010 uiiectoiy, then type

2E &75=#7=("*3 "*73!8&:

Now type %& anu %& "*73!8& to see if it has woikeu.
11 kemov|ng f||es and d|rector|es
rm (remove), rmd|r (remove d|rectory)

To uelete (iemove) a file, use the 62 commanu. The iesult of this is >,(K*$,$%!
It is not possible to unuelete files oi uiiectoiy, so make suie you know what you
aie uoing! As an example, we aie going to cieate a copy of the &75=#7=($D$ file,
then uelete it.

Insiue youi +,-.*%%/010 uiiectoiy, type

78 &75=#7=($D$ $=28@5%=($D$
%&
62 $=28@5%=($D$
%&

You can use the 62456 commanu to iemove a uiiectoiy (make suie it is empty
fiist). Tiy to iemove the "*73!8& uiiectoiy. You will not be able to since 0NIX
will not let you iemove a non-empty uiiectoiy.

Lxerc|se 2b

Cieate a uiiectoiy calleu $=28&$!@@ using 23456, then iemove it using the 62456
commanu.
11 D|sp|ay|ng the contents of a f||e on the screen
c|ear (c|ear screen)

Befoie you stait the next section, you may like to cleai the teiminal winuow of
the pievious commanus so the output of the following commanus can be cleaily
unueistoou.

At the piompt, type
16

7%=*6

This will cleai all text anu leave you with the !"!#$!F!"!#$!>BG piompt at the
top of the winuow.


cat (concatenate)

The commanu 7*$ can be useu to uisplay the contents of a file on the scieen.
Type:

7*$ &75=#7=($D$

As you can see, the file is longei than the size of the winuow, so it sciolls past
making it unieauable.

|ess

The commanu %=&& wiites the contents of a file onto the scieen a page at a time.
Type

%=&& &75=#7=($D$

Piess the |space-baij if you want to see anothei page, oi use |Page 0pj anu |Page
Bownj to move thiough the uocument. Type |qj if you want to quit ieauing. As
you can see, %=&& is useu in piefeience to 7*$ foi long files.

head

The ;=*4 commanu wiites the fiist ten lines of a file to the scieen.

Fiist cleai the scieen then type

;=*4 &75=#7=($D$

Then type

;=*4 )H &75=#7=($D$

What uiffeience uiu the )H uo to the ;=*4 commanu.

17
ta||

The $*5% commanu wiites the last ten lines of a file to the scieen.

Cleai the scieen anu type

$*5% &75=#7=($D$

Lxerc|se 4

Bow can you view the last 1S lines of the file.
12 1ab comp|et|on & command h|story

0buntu (as well as all othei Linux-baseu opeiating systems, incluuing Nac 0S X)
offei a gieat featuie calleu tab completion, which can save you a lot of time.
Whenevei you'ie typing the names of files, uiiectoiies, oi commanus in the
Teiminal, you can make it help you auto-complete the name by piessing the
|Tabj key. Foi instance , type

$*5% &7

anu then piess the |Tabj key. 0buntu will automatically complete the filename to
&75=#7=($D$ by looking in the uiiectoiy you'ie in (as well as some shaieu ones)
foi files, commanus, oi uiiectoiies whose name staits with &7. If theie is only one
unambiguous choice, it will select that one. If theie aie multiple options, it will
not auto-complete. You can make it show you a list of all files that stait with the
chaiacteis you have enteieu so fai by piessing |Tabj once moie. Type

78 &75=#7=($D$ &75=#$5@57($D$
$*5% &7

anu piess |Tabj aftei you've typeu &7. Now theie aie two files in the uiiectoiy
that stait with &7, so tab completion cannot choose foi you. It will howevei
complete it as fai as it can:

$*5% &75=#

If you piess |Tabj again, it will show you a list of the possible options:

&75=#7=($D$ &75=#$5@57($D$

18
By typing an auuitional 7, anu then piessing |Tabj again, you can make it auto-
complete the filename.

Anothei featuie that can save you a lot of time is cycling thiough the commanu
histoiy with the |0pj anu |Bownj aiiows. Piess the |0pj aiiow anu the Teiminal
will show you youi pievious commanu. 0nce you've founu the commanu you
want to iun again, you can just piess |Retuinj anu you will have saveu youiself
the time it takes to type the commanu. Piess the |Bownj aiiow to go foiwaiu in
youi commanu histoiy.
13 Search|ng the contents of a f||e
S|mp|e search|ng us|ng |ess

0sing %=&&, you can seaich though a text file foi a keywoiu (pattein). Foi
example, to seaich thiough &75=#7=($D$ foi the woiu 'science', type

%=&& &75=#7=($D$

then, still in %=&&, type a foiwaiu slash |j followeu by the woiu to seaich

:&75=#7=

As you can see, %=&& finus anu highlights the keywoiu. Type |nj to seaich foi the
next occuiience of the woiu.

grep (don't ask why |t |s ca||ed grep)

I6=8 is one of many stanuaiu 0NIX utilities. It seaiches files foi specifieu woius
oi patteins. Fiist cleai the scieen, then type

I6=8 &75=#7= &75=#7=($D$

As you can see, I6=8 has piinteu out each line containing the woiu science. 0i
has it. Tiy typing

I6=8 J75=#7= &75=#7=($D$

The I6=8 commanu is case sensitive; it uistinguishes between 'Science' anu
'science'. To ignoie uppeilowei case uistinctions, use the )5 option, i.e. type

I6=8 K5 &75=#7= &75=#7=($D$

19
To seaich foi a phiase oi pattein, you must enclose it in single quotes (the
apostiophe symbol). Foi example to seaich foi 'spinning top', type

I6=8 K5 L&85##5#I $<8L &75=#7=($D$

Some of the othei options of I6=8 aie:

)E uisplay those lines that uo N0T match
)# pieceue each matching line with the line numbei
)7 piint only the total count of matcheu lines

Tiy some of them anu see the uiffeient iesults. Bon't foiget, you can use moie
than one option at a time. Foi example, the numbei of lines without the woius
'science' oi 'Science' is

I6=8 K5E7 &75=#7= &75=#7=($D$

wc (word count)

A hanuy little utility is the 97 commanu, shoit foi woiu count. To uo a woiu
count on &75=#7=($D$, type

97 K9 &75=#7=($D$

To finu out how many lines the file has, type

97 K% &75=#7=($D$
14 ked|rect|on

Nost piocesses initiateu by commanus wiite to the stanuaiu output (that is, they
wiite to the teiminal scieen), anu many take theii input fiom the stanuaiu input
(that is, they ieau it fiom the keyboaiu). Theie is also the stanuaiu eiioi, wheie
piocesses wiite theii eiioi messages, by uefault, to the teiminal scieen.

We have alieauy seen one use of the 7*$ commanu to wiite the contents of a file
to the scieen.

Now type 7*$ without specifying a file to ieau

7*$

2u
Then type a few woius on the keyboaiu anu piess the |Retuinj key. Finally, holu
the |Ctilj key uown anu piess |uj (wiitten as ^B foi shoit) to enu the input.

What has happeneu. If you iun the 7*$ commanu without specifying a file to
ieau, it ieaus the stanuaiu input (the keyboaiu), anu on ieceiving the 'enu of file'
(^B), copies it to the stanuaiu output (the scieen).

We can ieuiiect both the input anu the output of commanus.
1S ked|rect|ng the Cutput

We use the M symbol to ieuiiect the output of a commanu. Foi example, to cieate
a file calleu %5&$1 containing a list of fiuit, type

7*$ M %5&$1

Then type in the names of some types of fiuits. Piess |Retuinj aftei each one.

8=*6
"*#*#*
*88%=
NC
Note: Remembei that NC means piessing |Ctilj anu |uj to stop

What happens is the cat commanu ieaus the stanuaiu input (the keyboaiu) anu
the M ieuiiects the output, which noimally goes to the scieen, into a file calleu
%5&$1.

To ieau the contents of the file, type

7*$ %5&$1

Lxerc|se S

0sing the above methou, cieate anothei file calleu %5&$/ containing the following
fiuit: oiange, plum, mango, giapefiuit. Reau the contents of %5&$/.

Append|ng to a f||e

The foim MM appenus stanuaiu output to a file, which means it is auueu to the
enu of the file. So to auu moie items to the file %5&$1, type

7*$ MM %5&$1

21
Then type in the names of moie fiuit

8=*7;
I6*8=
<6*#I=
NC

To ieau the contents of the file, type

7*$ %5&$1

You shoulu now have two files. 0ne contains six types of fiuit, the othei contains
foui types of fiuit. We will now use the 7*$ commanu to join (concatenate) %5&$1
anu %5&$/ into a new file calleu "5I%5&$. Type

7*$ %5&$1 %5&$/ M "5I%5&$

What this is uoing is ieauing the contents of %5&$1 anu %5&$/ in tuin, then
outputting the text to the file "5I%5&$.

To ieau the contents of the new file, type

7*$ "5I%5&$
16 ked|rect|ng the Input

We use the O symbol to ieuiiect the input of a commanu.

The commanu &<6$ alphabetically oi numeiically soits a list. Type

&<6$

Then type in the names of some animals. Piess |Retuinj aftei each one.

4<I
7*$
"564
*8=
NC

The output will be

*8=
22
"564
7*$
4<I

0sing O you can ieuiiect the input to come fiom a file iathei than the keyboaiu.
Foi example, to soit the list of fiuit, type

&<6$ O "5I%5&$

anu the soiteu list will be output to the scieen. We can ieveise the oiuei in
which the list is soiteu by using the )6 option. Type

&<6$ )6 O "5I%5&$

To output the soiteu list to a file, type,

&<6$ O "5I%5&$ M &%5&$

0se cat to ieau the contents of the file &%5&$.
17 |pes

We saw eailiei how we coulu get a list of the files anu uiiectoiies in oui home
uiiectoiy using the commanu %&. This commanu automatically soits this list foi
us. But what if we wanteu to get a list of all files anu uiiectoiies in ieveise oiuei,
i.e. fiom 'z' to 'a'. 0ne methou to get a soiteu list of names is to type,

%& B M #*2=&($D$
&<6$ K6 O #*2=&($D$

This is a bit slow anu you have to iemembei to iemove the tempoiaiy file calleu
names when you have finisheu. What you ieally want to uo is connect the output
of the %& commanu uiiectly to the input of the &<6$ commanu. This is exactly
what pipes uo. The symbol foi a pipe is the veitical bai P.

Foi example, typing

%& B P &<6$ )6

will give the same iesult as above, but quickei anu cleanei.

To finu out how many files anu uiiectoiies we have in oui home-uiiectoiy, type

2S
%& B P 97 )%

Lxerc|se 6

0sing pipes, uisplay all lines of %5&$1 anu %5&$/ containing the lettei 'p', anu soit
the iesult.
18 W||dcards
1he * w||dcard

The chaiactei Q is calleu a wilucaiu, anu will match against none oi moie
chaiactei(s) in a file (oi uiiectoiy) name. Foi example, in youi +,-.*%%/010
uiiectoiy, type

%& %5&$Q

This will list all files in the cuiient uiiectoiy staiting with %5&$....

Tiy typing

%& Q%5&$

This will list all files in the cuiient uiiectoiy enuing with ...%5&$.

1he ? w||dcard

The chaiactei R will match exactly one chaiactei. So R<!&= will match files like
;<!&= anu 2<!&=, but not I6<!&=.

Tiy typing

%& R%5&$
19 I||ename convent|ons

We shoulu note heie that a uiiectoiy is meiely a special type of file. So the iules
anu conventions foi naming files apply also to uiiectoiies. In naming files,
chaiacteis with special meanings such as : , Q, S, anu T, shoulu be avoiueu. Also,
avoiu using spaces within names. The safest way to name a file is to use only
alphanumeiic chaiacteis, that is, letteis anu numbeis, togethei with U
(unueiscoie) anu ( (uot).
24
20 Gett|ng ne|p
1he he|p opt|on

Nost commanus you will use in the 0buntu teiminal winuow will have some soit
of help message that tells you which options a paiticulai commanu can take, anu
how each option mouifies the behavioi of the commanu. This help message is
usually uisplayeu by invoking the commanu with the ));=%8 oi ); option. Some
commanus suppoit both, some suppoit only one of these, anu foi otheis these
two options might piouuce uiffeient help messages. Foi example, to finu out
moie about the &<6$ commanu, type

&<6$ ));=%8

In case the help message is too laige, you can pipe it to less to ieau thiough it
moie easily:

&<6$ K;=%8 P %=&&

man (manua|)

Theie aie also exist manual pages, which give you moie uetaileu infoimation
about most commanus. The manual pages tell you which options a paiticulai
commanu can take, anu how each option mouifies the behavioi of the commanu.
Type 2*# <commanu> to ieau the manual page foi a paiticulai commanu.

Foi example, to finu out moie about the 97 (woiu count) commanu, type

2*# 97

Alteinatively

9;*$5& 97

gives a one-line uesciiption of the 97 commanu, but omits any infoimation about
options etc.

apropos

When you aie not suie of the exact name of a commanu,

*86<8<& VWXYZ[C

2S
will give you the commanus with VWXYZ[C in theii manual page heauei. Foi
example, tiy typing

*86<8<& 7<8A
21 Chang|ng the keyboard |ayout to Dan|sh or US

0buntu has the 0SInteinational keyboaiu layout as its stanuaiu keyboaiu
layout. Foi those of you who have not memoiizeu wheie those keys aie locateu,
you can change the keyboaiu layout in 0buntu. Select ?I3(0= > P*0.0*02E03 >
U0IN),*6 anu go to the @*J'#% pane. Click on 1// anu select Banish fiom one of
the lists. Click on 1// within that selection winuow anu you shoulu now see
?,$K*(= as one of the possible keyboaiu layouts. If you'ie ceitain you only
want to use the Banish layout, move it to the top of the list using F'C, !>, click
on 1>>+J AJ-%,KRS)/,T anu it shoulu be switcheu to Banish.
22 Summary

6'KK*$/ F,*$)$L
%&
list files anu uiiectoiies
%& )*
list all files anu uiiectoiies
23456
make a uiiectoiy
74 456=7$<6A
change to nameu uiiectoiy
74
change to home-uiiectoiy
74 B
change to home-uiiectoiy
74 ((
change to paient uiiectoiy
894
uisplay the path of the cuiient uiiectoiy
78 @5%=1 @5%=/
copy file1 anu call it file2
2E @5%=1 @5%=/
move oi iename file1 to file2
62 @5%=
iemove a file
62456 456=7$<6A
iemove a uiiectoiy
7*$ @5%=
uisplay a file
%=&& @5%=
uisplay a file a page at a time
;=*4 @5%=
uisplay the fiist few lines of a file
$*5% @5%=
uisplay the last few lines of a file
I6=8 L3=A9<64L @5%=
seaich a file foi keywoius
97 @5%=
count numbei of lineswoiuschaiacteis in file
7<22*#4 M @5%=
ieuiiect stanuaiu output to a file
7<22*#4 MM @5%=
appenu stanuaiu output to a file
7<22*#4 O @5%=
ieuiiect stanuaiu input fiom a file
7<22*#41 P 7<22*#4/
pipe the output of commanu1 to the input of
commanu2
7*$ @5%=1 @5%=/ M @5%=0
concatenate file1 anu file2 to fileu
&<6$
soit uata
Q
match any numbei of chaiacteis
26
R
match one chaiactei
));=%8, ); uisplay the help message of a commanu
2*# 7<22*#4
ieau the online manual page foi a commanu
9;*$5& 7<22*#4
biief uesciiption of a commanu
*86<8<& 3=A9<64
match commanus with keywoiu in theii man
pages

You might also like