Académique Documents
Professionnel Documents
Culture Documents
What is UNIX?
UNIX is an operating system which was first developed in the 1960s, and has een !nder constant development ever since" #y operating system, we mean the s!ite of programs which ma$e the comp!ter wor$" It is a sta le, m!lti%!ser, m!lti%tas$ing system for servers, des$tops and laptops" UNIX systems also have a graphical !ser interface &'UI( similar to )icrosoft Windows which provides an easy to !se environment" *owever, $nowledge of UNIX is re+!ired for operations which aren,t covered y a graphical program, or for when there is no windows interface availa le, for e-ample, in a telnet session"
.ypes of UNIX
.here are many different versions of UNIX, altho!gh they share common similarities" .he most pop!lar varieties of UNIX are /!n /olaris, 'NU01in!-, and )ac2/ X" *ere in the /chool, we !se /olaris on o!r servers and wor$stations, and 3edora 1in!- on the servers and des$top 45s"
The kernel
.he $ernel of UNIX is the h! of the operating system7 it allocates time and memory to programs and handles the filestore and comm!nications in response to system calls" 8s an ill!stration of the way that the shell and the $ernel wor$ together, s!ppose a !ser types rm myfile &which has the effect of removing the file myfile(" .he shell searches the filestore for the file containing the program rm, and then re+!ests the
$ernel, thro!gh system calls, to e-ec!te the program rm on myfile" When the process rm myfile has finished r!nning, the shell then ret!rns the UNIX prompt 9 to the !ser, indicating that it is waiting for f!rther commands"
The shell
.he shell acts as an interface etween the !ser and the $ernel" When a !ser logs in, the login program chec$s the !sername and password, and then starts another program called the shell" .he shell is a command line interpreter &51I(" It interprets the commands the !ser types in and arranges for them to e carried o!t" .he commands are themselves programs7 when they terminate, the shell gives the !ser another prompt &9 on o!r systems(" .he adept !ser can c!stomise his0her own shell, and !sers can !se different shells on the same machine" /taff and st!dents in the school have the tcsh shell y defa!lt" .he tcsh shell has certain feat!res to help the !ser inp!tting commands" 3ilename 5ompletion % #y typing part of the name of a command, filename or directory and pressing the :Tab; $ey, the tcsh shell will complete the rest of the name a!tomatically" If the shell finds more than one name eginning with those letters yo! have typed, it will eep, prompting yo! to type a few more letters efore pressing the ta $ey again" *istory % .he shell $eeps a list of the commands yo! have typed in" If yo! need to repeat a command, !se the c!rsor $eys to scroll !p and down the list or type history for a list of previo!s commands"
<-amples of files7
a doc!ment &report, essay etc"( the te-t of a program written in some high%level programming lang!age instr!ctions comprehensi le directly to the machine and incomprehensi le to a cas!al !ser, for e-ample, a collection of inary digits &an e-ec!ta le or inary file(6 a directory, containing information a o!t its contents, which may e a mi-t!re of other directories &s! directories( and ordinary files"
In the diagram a ove, we see that the home directory of the !ndergrad!ate st!dent "ee51vn" contains two s! %directories &docs and pics( and a file called report.doc" .he f!ll path to the file report.doc is "/home/its/u 1/ee51vn/report.doc"
.o open an UNIX terminal window, clic$ on the >.erminal> icon from the drop%down men!s"
8n UNIX .erminal window will then appear with a 9 prompt, waiting for yo! to start entering commands"
% ls
.he ls command lists the contents of yo!r c!rrent wor$ing directory"
.here may e no files visi le in yo!r home directory, in which case, the UNIX prompt will e ret!rned" 8lternatively, there may already e some files inserted y the /ystem 8dministrator when yo!r acco!nt was created" ls does not, in fact, ca!se all the files in yo!r home directory to e listed, !t only those ones whose name does not egin with a dot &"( 3iles eginning with a dot &"( are $nown as hidden files and !s!ally contain important program config!ration
information" .hey are hidden eca!se yo! sho!ld not change them !nless yo! are very familiar with UNIX@@@ .o list all files in yo!r home directory incl!ding those whose names egin with a dot, type
% ls -a
8s yo! can see, ls -a lists files that are normally hidden"
ls is an e-ample of a command which can ta$e options7 %a is an e-ample of an option" .he options change the ehavio!r of the command" .here are online man!al pages that tell yo! which options a partic!lar command can ta$e, and how each option modifies the ehavio!r of the command" &/ee later in this t!torial(
% mkdir unixstuff
.o see the directory yo! have B!st created, type
% ls
% cd unixstuff
.ype ls to see the contents &which sho!ld e empty(
&'ercise 1a
)a$e another directory inside the uni'stuff directory called backups
% ls -a
8s yo! can see, in the uni'stuff directory &and in all other directories(, there are two special directories called &.( and &..(
% cd .
N2.<7 there is a space etween cd and the dot
.his may not seem very !sef!l at first, !t !sing &.( as the name of the c!rrent directory will save a lot of typing, as we shall see later in the t!torial"
% cd ..
will ta$e yo! one directory !p the hierarchy & ac$ to yo!r home directory(" .ry it now" Note7 typing cd with no arg!ment always ret!rns yo! to yo!r home directory" .his is very !sef!l if yo! are lost in the file system"
1"E 4athnames
p(d "print (orkin directory#
4athnames ena le yo! to wor$ o!t where yo! are in relation to the whole file% system" 3or e-ample, to find o!t the a sol!te pathname of yo!r home%directory, type cd to get ac$ to yo!r home%directory and then type
% pwd
.he f!ll pathname will loo$ something li$e this %
/home/its/ug1/ee51vn
which means that ee51vn &yo!r home directory( is in the s! %directory u 1 &the gro!p directory(,which in t!rn is located in the its s! %directory, which is in the home s! %directory, which is in the top%level root directory called > / " "
&'ercise 1b
Use the commands cd, ls and pwd to e-plore the file system" &Femem er, if yo! get lost, type cd y itself to ret!rn to yo!r home%directory(
% ls unixstuff
to list the conents of yo!r !ni-st!ff directory" Now type
% ls backups
?o! will get a message li$e this %
.he reason is, backups is not in yo!r c!rrent wor$ing directory" .o !se a command on a file &or directory( not in the c!rrent wor$ing directory &the directory yo! are c!rrently in(, yo! m!st either cd to the correct directory, or specify its f!ll pathname" .o list the contents of yo!r ac$!ps directory, yo! m!st type
% ls unixstuff/backups
% ls ~/unixstuff
will list the contents of yo!r !ni-st!ff directory, no matter where yo! c!rrently are in the file system" What do yo! thin$
% ls ~
wo!ld list? What do yo! thin$
% ls ~/..
wo!ld list?
/!mmary
*ommand ls ls -a +eanin list files and directories list all files and directories
mkdir
ma$e a directory
cd directory change to named directory cd cd ~ cd .. pwd change to home%directory change to home%directory change to parent directory display the path of the c!rrent directory
% cd ~/unixstuff
.hen at the UNIX prompt, type,
% cp /vol/examples/tutorial/science.txt .
Note7 =on,t forget the dot . at the end" Femem er, in UNIX, the dot means the c!rrent directory"
.he a ove command means copy the file science.t't to the c!rrent directory, $eeping the name the same"
&Note7 .he directory /vol/e'amples/tutorial/ is an area to which everyone in the school has read and copy access" If yo! are from o!tside the University, yo! can gra a copy of the file here" Use ,3ile0/ave 8s"", from the men! ar to save it into yo!r uni'stuff directory"(
&'ercise ,a
5reate a ac$!p of yo!r science.t't file y copying it to a file called science.bak
% mv science.bak backups/.
.ype ls and ls ac$!ps to see if it has wor$ed"
.o delete &remove( a file, !se the rm command" 8s an e-ample, we are going to create a copy of the science.t't file then delete it" Inside yo!r uni'stuff directory, type
&'ercise ,b
5reate a directory called tempstuff !sing mkdir , then remove it !sing the rmdir command"
% clear
.his will clear all te-t and leave yo! with the 9 prompt at the top of the window"
cat "concatenate#
.he command cat can e !sed to display the contents of a file on the screen" .ype7
% cat science.txt
8s yo! can see, the file is longer than than the siGe of the window, so it scrolls past ma$ing it !nreada le"
less
.he command less writes the contents of a file onto the screen a page at a time" .ype
% less science.txt
4ress the :space%bar; if yo! want to see another page, and type :.; if yo! want to +!it reading" 8s yo! can see, less is !sed in preference to cat for long files"
head
.he head command writes the first ten lines of a file to the screen" 3irst clear the screen then type
% head science.txt
.hen type
% head -
science.txt
tail
.he tail command writes the last ten lines of a file to the screen" 5lear the screen and type
% tail science.txt
H" *ow can yo! view the last 1E lines of the file?
Using less, yo! can search tho!gh a te-t file for a $eyword &pattern(" 3or e-ample, to search thro!gh science.t't for the word 0science0, type
% less science.txt
then, still in less, type a forward slash :/; followed y the word to search
/science
8s yo! can see, less finds and highlights the $eyword" .ype :n; to search for the ne-t occ!rrence of the word"
rep#
!rep is one of many standard UNIX !tilities" It searches files for specified words or patterns" 3irst clear the screen, then type
(c "(ord count#
8 handy little !tility is the wc command, short for word co!nt" .o do a word co!nt on science.t't, type
% wc -w science.txt
.o find o!t how many lines the file has, type
% wc -l science.txt
/!mmary
*ommand cp file1 file2 +eanin copy file1 and call it fileA
mv file1 file2 rm file rmdir directory cat file less file head file tail file
move or rename file1 to fileA remove a file remove a directory display a file display a file a page at a time display the first few lines of a file display the last few lines of a file
!rep 'keyword' file search a file for $eywords wc file co!nt n!m er of lines0words0characters in file
% cat
.hen type a few words on the $ey oard and press the :1eturn; $ey"
3inally hold the :*trl; $ey down and press :d; &written as 23 for short( to end the inp!t" What has happened? If yo! r!n the cat command witho!t specifing a file to read, it reads the standard inp!t &the $ey oard(, and on receiving the ,end of file, &23(, copies it to the standard o!tp!t &the screen(" In UNIX, we can redirect oth the inp!t and the o!tp!t of commands"
% cat $ list%
.hen type in the names of some fr!it" 4ress :1eturn; after each one"
pear banana apple &' (this means press )*trl+ and )d+ to stop,
What happens is the cat command reads the standard inp!t &the $ey oard( and the I redirects the o!tp!t, which normally goes to the screen, into a file called list1 .o read the contents of the file, type
% cat list%
&'ercise 4a
Using the a ove method, create another file called list, containing the following fr!it7 orange, pl!m, mango, grapefr!it" Fead the contents of list,
4.,.1 5ppendin
to a file
.he form II appends standard o!tp!t to a file" /o to add more items to the file list1, type
% cat $$ list%
.hen type in the names of more fr!it
% cat list%
?o! sho!ld now have two files" 2ne contains si- fr!it, the other contains fo!r fr!it" We will now !se the cat command to Boin &concatenate( list1 and list, into a new file called bi list" .ype
% cat bi!list
% sort
.hen type in the names of some animals" 4ress :Fet!rn; after each one"
% sort 0 bi!list
and the sorted list will e o!tp!t to the screen" .o o!tp!t the sorted list to a file, type,
C"D 4ipes
.o see who is on the system with yo!, type
% who
2ne method to get a sorted list of names is to type,
.his is a it slow and yo! have to remem er to remove the temporary file called names when yo! have finished" What yo! really want to do is connect the o!tp!t of the who command directly to the inp!t of the sort command" .his is e-actly what pipes do" .he sym ol for a pipe is the vertical ar K 3or e-ample, typing
% who 1 sort
will give the same res!lt as a ove, !t +!ic$er and cleaner" .o find o!t how many !sers are logged on, type
% who 1 wc -l
&'ercise 4b
Using pipes, display all lines of list1 and list, containing the letter ,p,, and sort the res!lt" 8nswer availa le here
/!mmary
*ommand command $ file command $$ file command 0 file command1 1 command2 +eanin redirect standard o!tp!t to a file append standard o!tp!t to a file redirect standard inp!t from a file pipe the o!tp!t of command1 to the inp!t of commandA
cat file1 file2 $ file0 concatenate file1 and fileA to file0 sort who sort data list !sers c!rrently logged in
% ls list2
.his will list all files in the c!rrent directory starting with list.... .ry typing
% ls 2list
.his will list all files in the c!rrent directory ending with ....list
The 8 (ildcard
.he character 3 will match e-actly one character" /o 8ouse will match files li$e house and mouse, !t not .ry typing rouse"
% ls 3list
In naming files, characters with special meanings s!ch as / 7 9 : , sho!ld e avoided" 8lso, avoid !sing spaces within names" .he safest way to name a file is to !se only alphan!meric characters, that is, letters and n!m ers, together with L &!nderscore( and " &dot("
3ile names conventionally start with a lower%case letter, and may end with a dot followed y a gro!p of letters indicating the contents of the file" 3or e-ample, all files consisting of 5 code may e named with the ending .c, for e-ample, pro 1.c " .hen in order to list all files containing 5 code in yo!r home directory, yo! need only type ls 2.c in that directory"
% man wc
8lternatively
% whatis wc
gives a one%line description of the command, !t omits any information a o!t options etc"
5propos
When yo! are not s!re of the e-act name of a command,
% apropos keyword
will give yo! the commands with $eyword in their man!al page header" 3or e-ample, try typing
% apropos copy
/!mmary
*ommand 2 3 man command whatis command +eanin match any n!m er of characters match one character read the online man!al page for a command rief description of a command
<ach file &and directory( has associated access rights, which may e fo!nd y typing ls -l" 8lso, ls -l! gives additional information as to which gro!p owns the file & eng9E in the following e-ample(7
In the left%hand col!mn is a 10 sym ol string consisting of the sym ols d, r, w, -, %, and, occasionally, s or /" If d is present, it will e at the left hand end of the string, and indicates a directory7 otherwise % will e the starting sym ol of the string" .he 9 remaining sym ols indicate the permissions, or access rights, and are ta$en as three gro!ps of C"
.he left gro!p of C gives the file permissions for the !ser that owns the file &or directory( &eeE1a in the a ove e-ample(6 the middle gro!p gives the permissions for the gro!p of people to whom the file &or directory( elongs &ee eng9E in the a ove e-ample(6 the rightmost gro!p gives the permissions for all others"
.he sym ols r, w, etc", have slightly different meanings depending on whether they refer to a simple file or to a directory"
- &or %(, indicates e-ec!tion permission &or otherwise(, that is, the permission to e-ec!te a file, where appropriate
/o, in order to read a file, yo! m!st have e-ec!te permission on the directory containing that file, and hence on any directory containing that directory as a s! directory, and so on, !p the tree"
/ome e'amples
%rw-rw-rw- a file that everyone can read, write and e-ec!te &and delete(" a file that only the owner can read and write % no%one else %rw%%%%%%% can read or write and no%one has e-ec!tion rights &e"g" yo!r mail o- file("
2nly the owner of a file can !se chmod to change the permissions of a file" .he options of chmod are as follows
+eanin
w N %
write &and delete( e-ec!te &and access directory( add permission ta$e away permission
3or e-ample, to remove read write and e-ec!te permissions on the file bi list for the gro!p and others, type
&'ercise 5a
.ry changing access permissions on the file science.t't and on the directory backups Use ls -l to chec$ that the permissions have changed"
% ps
8 process may e in the foregro!nd, in the ac$gro!nd, or e s!spended" In general the shell does not ret!rn the UNIX prompt !ntil the c!rrent process has finished e-ec!ting"
/ome processes ta$e a long time to r!n and hold !p the terminal" #ac$gro!nding a long process has the effect that the UNIX prompt is ret!rned immediately, and other tas$s can e carried o!t while the original process contin!es e-ec!ting"
1unnin
.o ac$gro!nd a process, type an 9 at the end of the command line" 3or e-ample, the command sleep waits a given n!m er of seconds efore contin!ing" .ype
% sleep %7
.his will wait 10 seconds efore ret!rning the command prompt 9" Until the command prompt is ret!rned, yo! can do nothing e-cept wait" .o r!n sleep in the ac$gro!nd, type
% sleep %7 9
)%+ :/ 5
.he 9 r!ns the Bo in the ac$gro!nd and ret!rns the prompt straight away, allowing yo! do r!n other programs while waiting for that one to finish" .he first line in the a ove e-ample is typed in y the !ser6 the ne-t line, indicating Bo n!m er and 4I=, is ret!rned y the machine" .he !ser is e notified of a Bo n!m er &n!m ered from 1( enclosed in s+!are rac$ets, together with a 4I= and is notified when a ac$gro!nd process is finished" #ac$gro!nding is !sef!l for Bo s which will ta$e a long time to complete"
<ack roundin
8t the prompt, type
% sleep %777
?o! can s!spend the process r!nning in the foregro!nd y typing 2=, i"e"hold down the :*trl; $ey and type :>;" .hen to p!t it in the ac$gro!nd, type
% b!
% ;obs
8n e-ample of a Bo list co!ld e
)%+ "uspended sleep %777 )/+ <unnin! netscape )=+ <unnin! matlab
.o restart &foregro!nd( a s!spended processes, type
% f! %jobnumber
3or e-ample, to restart sleep 1000, type
% f! %%
.yping f! with no Bo n!m er foregro!nds the last s!spended process"
% kill %jobnumber
3or e-ample, r!n
% kill %6
.o chec$ whether this has wor$ed, e-amine the Bo list again to see if the process has een removed"
ps "process status#
8lternatively, processes can e $illed y finding their process n!m ers &4I=s( and !sing $ill PID_number
% sleep %777 9 % ps
>?' @@ " @?AB /77EE pts/ " /% := pts/ @ /%FE= pts/ "
% kill /77EE
and then type ps again to see if it has een removed from the list" If a process ref!ses to e $illed, !ses the %$ option, i"e" type
% kill -5 /77EE
Note7 It is not possi le to $ill off other !sers, processes @@@
/!mmary
*ommand ls -la! +eanin list access rights for all files
chmod )options+ file change access rights for named file command 9 &* &G b! ;obs f! %% kill %% ps kill /:% / r!n command in ac$gro!nd $ill the Bo r!nning in the foregro!nd s!spend the Bo r!nning in the foregro!nd ac$gro!nd the s!spended Bo list c!rrent Bo s foregro!nd Bo n!m er 1 $ill Bo n!m er 1 list c!rrent processes $ill process n!m er A61EA
% Huota -v
df
.he df command reports on the space left on the file system" 3or e-ample, to find o!t how m!ch space is left on the fileserver, type
% df .
du
.he du command o!tp!ts the n!m er of $ilo yes !sed y each s! directory" Usef!l if yo! have gone over +!ota and yo! want to find o!t which directory has the most files" In yo!r home%directory, type
% du -s 2
.he %s flag will display only a s!mmary &total siGe( and the R means all files and directories"
>ip
.his red!ces the siGe of a file, th!s freeing val!a le dis$ space" 3or e-ample, type
% ls -l science.txt
and note the siGe of the file !sing ls -l " .hen to compress science"t-t, type
% !Iip science.txt
.his will compress the file and place it in a file called science.t't. > .o see the change in siGe, type ls -l again" .o e-pand the file, !se the !unIip command"
% !unIip science.txt.!I
>cat
Icat will read gGipped files witho!t needing to !ncompress them first"
% Icat science.txt.!I
If the te-t scrolls too fast for yo!, pipe the o!tp!t tho!gh less "
file
file classifies the named files according to the type of data they contain, for e-ample ascii &te-t(, pict!res, compressed data, etc"" .o report on all files in yo!r home directory, type
% file 2
diff
.his command compares the contents of two files and displays the differences" /!ppose yo! have a file called file1 and yo! edit some part of it and save it as file," .o see the differences type
find
.his searches thro!gh the directories for files and directories with a given name, date, siGe, or any other attri !te yo! care to specify" It is a simple command !t with many options % yo! can read the man!al y typing man find" .o search for all fies with the e-tention .t't, starting at the c!rrent directory &"( and wor$ing thro!gh all s! %directories, then printing the name of the file to the screen, type
history
.he 5 shell $eeps an ordered list of all the commands that yo! have entered" <ach command is given a n!m er according to the order it was entered"
% 44 -recall last command. % 4-= -recall third most recent command. % 4 -recall th command in list.
% set historyK%77
1ocate and download the so!rce code &which is !s!ally compressed( Unpac$ the so!rce code 5ompile the code
2f the a ove steps, pro a ly the most diffic!lt is the compilation stage"
*ompilin
/ource *ode
8ll high%level lang!age code m!st e converted into a form the comp!ter !nderstands" 3or e-ample, 5 lang!age so!rce code is converted into a lower%level lang!age called assem ly lang!age" .he assem ly lang!age code made y the previo!s stage is then converted into o Bect code which are fragments of code which the comp!ter !nderstands directly" .he final stage in compiling a program involves lin$ing the o Bect code to code li raries which contain certain !ilt%in f!nctions" .his final stage prod!ces an e-ec!ta le program" .o do all these steps y hand is complicated and eyond the capa ility of the ordinary !ser" 8 n!m er of !tilities and tools have een developed for programmers and end%!sers to simplify these steps"
confi ure
8s the n!m er of UNIX variants increased, it ecame harder to write programs which co!ld r!n on all variants" =evelopers fre+!ently did not have access to every system, and the characteristics of some systems changed from version to version" .he 'NU config!re and !ild system simplifies the !ilding of programs distri !ted as so!rce code" 8ll programs are !ilt !sing a simple, standardised, two step process" .he program !ilder need not install any special tools in order to !ild the program" .he confi!ure shell script attempts to g!ess correct val!es for vario!s system% dependent varia les !sed d!ring compilation" It !ses those val!es to create a +akefile in each directory of the pac$age" .he simplest way to compile a pac$age is7
1. 2. 3. 4. 5.
6.
cd to the directory containing the pac$age,s so!rce code" .ype ./confi!ure to config!re the pac$age for yo!r system" .ype make to compile the pac$age" 2ptionally, type make check to r!n any self%tests that come with the pac$age" .ype make install to install the programs and any data files and doc!mentation" 2ptionally, type make clean to remove the program inaries and o Bect files from the so!rce code directory
.he config!re !tility s!pports a wide variety of options" ?o! can !s!ally !se the %%help option to get a list of interesting options for a partic!lar config!re script" .he only generic options yo! are li$ely to !se are the %%prefi' and %%e'ec%prefi' options" .hese options are !sed to specify the installation directories" .he directory named y the %%prefi' option will hold machine independent files s!ch as doc!mentation, data and config!ration files" .he directory named y the %%e'ec%prefi' option, &which is normally a s! directory of the %%prefi' directory(, will hold machine dependent files s!ch as e-ec!ta les"
% mkdir download
=ownload the software here and save it to yo!r new download directory"
% cd download % ls -l
8s yo! can see, the filename ends in tar"gG" .he tar command t!rns several files and directories into one single tar file" .his is then compressed !sing the gGip command &to create a tar"gG file(" 3irst !nGip the file !sing the g!nGip command" .his will create a "tar file"
% !unIip units-%.E6.tar.!I
.hen e-tract the contents of the tar file"
% cd units-%.E6
% mkdir ~/units%E6
.hen r!n the config!re !tility setting the installation path to this"
% ./confi!ure --prefixKLMCAB/units%E6
N2.<7 .he FG!+& varia le is an e-ample of an environment varia le" .he val!e of FG!+& is the path to yo!r home directory" O!st type
% echo LMCAB
to show the contents of this varia le" We will learn more a o!t environment varia les in a later chapter" If confi!ure has r!n correctly, it will have created a )a$efile with all necessary options" ?o! can view the )a$efile if yo! wish &!se the less command(, !t do not edit the contents of this"
% make
8fter a min!te or two &depending on the speed of the comp!ter(, the e-ec!ta les will e created" ?o! can chec$ to see everything compiled s!ccessf!lly y typing
% make check
If everything is o$ay, yo! can now install the pac$age"
% make install
.his will install the files into the )/units1CD directory yo! created earlier"
% cd ~/units%E6
If yo! list the contents of the !nits directory, yo! will see a n!m er of s! directories"
in info man
.he inary e-ec!ta les 'NU info formatted doc!mentation )an pages
% ./units
8s an e-ample, convert 6 feet to metres"
2 %.F/FF
If yo! get the answer 1"SASS, congrat!lations, it wor$ed" .o view what !nits it can convert etween, view the data file in the share directory &the list is +!ite comprehensive(" .o read the f!ll doc!mentation, change into the info directory and type
% info --fileKunits.info
.his is !sef!l for the programmer, !t !nnecessary for the !ser" We can ass!me that the pac$age, once finished and availa le for download has already een tested and de !gged" *owever, when we compiled the software a ove, de !gging information was still compiled into the final e-ec!ta le" /ince it is !nli$ey that we are going to need this de !gging information, we can strip it o!t of the final e-ec!ta le" 2ne of the advantages of this is a m!ch smaller e-ec!ta le, which sho!ld r!n slightly faster" What we are going to do is loo$ at the efore and after siGe of the inary file" 3irst change into the bin directory of the !nits installation directory"
% cd ~/units%E6/bin % ls -l
8s yo! can see, the file is over 100 $ ytes in siGe" ?o! can get more information on the type of file y !sing the file command"
% file units
units: BOP =/-bit O"Q executable, ?ntel F7=F:, version %, dynamically linked -uses shared libs., not stripped
.o strip all the de !g and line n!m ering information o!t of the inary file, !se the strip command
% strip units % ls -l
8s yo! can see, the file is now C6 $ ytes % a third of its original siGe" .wo thirds of the inary file was de !g code@@@ 5hec$ the file information again"
% file units
units: BOP =/-bit O"Q executable, ?ntel F7=F:, version %, dynamically linked -uses shared libs., stripped
/ometimes yo! can !se the make command to install pre%stripped copies of all the inary files when yo! install the pac$age" Instead of typing make install, simply type make install-strip
% echo LC"@N>B
)ore e-amples of environment varia les are
U/<F &yo!r login name( *2)< &the path name of yo!r home directory( *2/. &the name of the comp!ter yo! are !sing( 8F5* &the architect!re of the comp!ters processor( =I/418? &the name of the comp!ter screen to display X windows( 4FIN.<F &the defa!lt printer to send print Bo s( 48.* &the directories the shell sho!ld search to find a command(
6indin
<NTIF2N)<N. varia les are set !sing the setenv command, displayed !sing the printenv or env commands, and !nset !sing the unsetenv command" .o show all val!es of these varia les, type
% printenv 1 less
cwd &yo!r c!rrent wor$ing directory( home &the path name of yo!r home directory( path &the directories the shell sho!ld search to find a command( prompt &the te-t string !sed to prompt for interactive commands shell yo!r login shell(
6indin
/*<11 varia les are oth set and displayed !sing the set command" .hey can e !nset y !sing the !nset command" .o show all val!es of these varia les, type
% set 1 less
<ach time the shell varia les home, !ser and term are changed, the corresponding environment varia les *2)<, U/<F and .<F) receive the same val!es" *owever, altering the environment varia les has no effect on the corresponding shell varia les" 48.* and path specify directories to search for commands and programs" #oth varia les always represent the same directory list, and altering either a!tomatically ca!ses the other to e changed"
I51NIN;J N<T<F p!t commands that r!n graphical displays &e"g" a we in yo!r "cshrc or "login file"
rowser(
% echo Lhistory
*owever, this has only set the varia le for the lifetime of the c!rrent shell" If yo! open a new -term window, it will only have the defa!lt history val!e set" .o 4<F)8N<N.1? set the val!e of history, yo! will need to add the set command to the "cshrc file" 3irst open the .cshrc file in a te-t editor" 8n easy, !ser%friendly editor to !se is nedit"
% nedit ~/.cshrc
8dd the following line 83.<F the list of other commands" set history U A00 /ave the file and force the shell to reread its "cshrc file !y !sing the shell so!rce command"
% source .cshrc
5hec$ this has wor$ed y typing
% echo Lhistory
?o! can add it to the end of yo!r e-isting path &the Fpath represents this( y iss!ing the command7
% cd % units
.o add this path 4<F)8N<N.1?, add the following line to yo!r "cshrc 83.<F the list of other commands"