Vous êtes sur la page 1sur 48


Sl No. Topic Page No
1. SESSION-1: MCS 041 03 2
!I"#$o%&c#io" #o '"i()
2. SESSION-2: MCS 043 30 3*
!+BMS La,)
MCS-041: I"#$o%&c#io" #o '"i(
1) E(plo$e All 'NI- Co..a"%/ gi0e" i" #1i/ .a"&al.
l/ --- lists your files.
l/ -l --- lists your files in 'long format', which contains lots of useful
information, e.g. the exact size of the file, who owns the file and who
has the right to look at it, and when it was last modified.
l/ -a --- lists all files, including the ones whose filenames begin in a
dot, which you do not always want to see.
There are many more options, for example to list files by size, by
date, recursively etc.
.o$e 2ile"a.e --- shows the first part of a file, just as much as will fit
on one screen. ust hit the space bar to see more or 3 to !uit. "ou
can use 4pa##e$" to search for a pattern.
e.ac/ 2ile"a.e --- is an editor that lets you create and edit a file. .0
2ile"a.e1 2ile"a.e2 --- moves a file #i.e. gives it a different name, or
moves it into a different directory #see below$.
cp 2ile"a.e1 2ile"a.e2 --- copies a file
$. 2ile"a.e --- removes a file. %t is wise to use the option rm -i, which
will ask you for confirmation before actually deleting anything. "ou
can make this your default by making an alias in your .cshrc file.
%i22 2ile"a.e1 2ile"a.e2 --- compares files, and shows where they
5c 2ile"a.e --- tells you how many lines, words, and characters
there are in a file
c1.o% op#io"/ 2ile"a.e --- lets you change the read, write, and
execute permissions on your files. The default is that only you can
look at them and change them, but you may sometimes want to
change these permissions. &or example, c1.o% o6$ 2ile"a.e will
make the file readable for everyone, and c1.o% o-$ 2ile"a.e will
make it unreadable for others again. 'ote that for someone to be able
to actually look at the file the directories it is in need to be at least
&ile (ompression
o g7ip 2ile"a.e --- compresses files, so that they take up much
less space. )sually text files compress to about half their
original size, but it depends very much on the size of the file
and the nature of the contents. There are other tools for this
purpose, too #e.g. co.p$e//$, but gzip usually gives the
highest compression rate. *zip produces files with the ending
'.gz' appended to the original filename.
o g&"7ip filename --- uncompresses files compressed by gzip.
o g7ca# filename --- lets you look at a gzipped file without
actually having to gunzip it #same as g&"7ip -c$. "ou can even
print it directly, using g7ca# filename 8 lp$
o lp$ filename --- print. )se the -+ option to specify the printer
name if you want to use a printer other than your default printer.
&or example, if you want to print double-sided, use 'lpr -+valkyr-
d', or if you're at (,-%, you may want to use 'lpr -+cord../-d'.
,ee 'help printers' for more information about printers and their
o lp3 --- check out the printer !ueue, e.g. to get the number
needed for removal, or to see how many other files will be
printed before yours will come out
o lp$. jobnumber --- remove something from the printer !ueue.
"ou can find the job number by using lp!. Theoretically you also
have to specify a printer name, but this isn't necessary as long
as you use your default printer in the department.
o ge"/c$ip# --- converts plain text files into postscript for printing,
and gives you some options for formatting. (onsider making an
alias like alia/ ecop 9ge"/c$ip# -2 -$ :;< 8 lp$ -1 -P0al=>$9 to
print two pages on one piece of paper.
o dvips filename --- print .dvi files #i.e. files produced by -aTe0$.
"ou can use dviselect to print only selected pages.
1irectories, like folders on a 2acintosh, are used to group files together in a
hierarchical structure.
.=%i$ dirname --- make a new directory
c% dirname --- change directory. "ou basically 'go' to another
directory, and you will see the files in that directory when you do 'ls'.
"ou always start out in your 'home directory', and you can get back
there by typing 'cd' without arguments. 'cd ..' will get you one level up
from your current position. "ou don't have to walk along step by step -
you can make big leaps or avoid walking around by specifying
p5% --- tells you where you currently are.
Fi"%i"g #1i"g/
22 --- find files anywhere on the system. This can be extremely useful
if you've forgotten in which directory you put a file, but do remember
the name. %n fact, if you use 22 -p you don't even need the full name,
just the beginning. This can also be useful for finding other things on
the system, e.g. documentation.
g$ep string filename(s) --- looks for the string in the files. This can
be useful a lot of purposes, e.g. finding the right file among many,
figuring out which is the right version of something, and even doing
serious corpus work. grep comes in several varieties #g$ep, eg$ep,
and 2g$ep$ and has a lot of very flexible options. (heck out the man
pages if this sounds good to you.
5$i#e username --- lets you exchange one-line messages with
another user
el. --- lets you send e-mail messages to people around the world
#and, of course, read them$. %t's not the only mailer you can use, but
the one we recommend. ,ee the elm page, and find out about the
departmental mailing lists #which you can also find in
A,o&# >o&$ !elec#$o"ic) /el2
51oa.i --- returns your username. ,ounds useless, but isn't. "ou
may need to find out who it is who forgot to log out somewhere, and
make sure 4you4 have logged out.
2i"ge$ 5 .plan files
of course you can finger yourself, too. That can be useful e.g. as a
!uick check whether you got new mail. Try to create a useful .plan file
soon. -ook at other people's .plan files for ideas. The file needs to be
readable for everyone in order to be visible through 'finger'. 1o
'chmod a6r .plan' if necessary. "ou should realize that this information
is accessible from anywhere in the world, not just to other people on
pa//5% --- lets you change your password, which you should do
regularly #at least once a year$.
p/ -& yourusername --- lists your processes. (ontains lots of
information about them, including the process %1, which you need if
you have to kill a process. 'ormally, when you have been kicked out
of a dialin session or have otherwise managed to get yourself
disconnected abruptly, this list will contain the processes you need to
kill. Those may include the shell #tcsh or whatever you're using$, and
anything you were running, for example emacs or elm. 7e careful not
to kill your current shell - the one with the number closer to the one of
the ps command you're currently running. 7ut if it happens, don't
panic. ust try again 8$ %f you're using an 0-display you may have to
kill some 0 processes before you can start them again. These will
show only when you use p/ -e2l, because they're root processes.
=ill PID --- kills #ends$ the processes with the %1 you gave. This works
only for your own processes, of course. *et the %1 by using p/. %f the
process doesn't 'die' properly, use the option -9. 7ut attempt without
that option first, because it doesn't give the process a chance to finish
possibly important business before dying. "ou may need to kill
processes for example if your modem connection was interrupted and
you didn't get logged out properly, which sometimes happens.
3&o#a -0 --- show what your disk !uota is #i.e. how much space you
have to store files$, how much you're actually using, and in case
you've exceeded your !uota #which you'll be given an automatic
warning about by the system$ how much time you have left to sort
them out #by deleting or gzipping some, or moving them to your own
%& filename --- shows the disk usage of the files and directories in
filename #without argument the current directory is used$. %& -/ gives
only a total.
la/# yourusername --- lists your last logins. (an be a useful memory
aid for when you were where, how long you've been working for, and
keeping track of your phonebill if you're making a non-local phonecall
for dialling in.
2) C$ea#e a %i$ec#o$>.
To create a directory, use the mkdir command. &or example, to create a
directory named ,tudent within the current working directory8
? .=%i$ S#&%e"#
3) C$ea#e a S&,%i$ec#o$> i" #1e %i$ec#o$> c$ea#e%.
"ou may create a subdirectory within any directory where you have write
permission. &or example, to create a directory
called3,tudent3,ubdirectory., assuming that directory 3,tudent already
? .=%i$ 4S#&%e"#4S&,%i$ec#o$>1
4) C1a"ge >o&$ c&$$e"# %i$ec#o$> #o #1e /&,%i$ec#o$>.
To change the current working directory to the subdirectory, use the the cd
command #this stands for :change directory:$. ;ssuming that the current
working 1irectory is ,tudent, to change to the subdirectory ,ubdirectory.8
? c% S&,%i$ec#o$>1
*) +i/pla> Cale"%e$ 2o$ #1e c&$$e"# Mo"#1.
To display (alender for the current month use the (;- command.
@) Ae# a %i$ec#o$> li/#i"g o2 #1e pa$e"# %i$ec#o$>.
To get the 1irectory listing of the parent directory, use the command
ls - list contents of directory.
*oto the parent directory and use ls command.
? l/
B) Co5 .a"> &/e$/ 5e$e logge% o"#o >o&$ />/#e..
To see all the other users that are currently connected to system simply use
the following command who. This will simply print out a list of all the users
connected #just their usernames however, not their real names$, the
terminal they're connected to, when they connected and where they
connected from.
? 51o
<owever to !uickly see roughly what the other users of the system are up
to use the following command8 = w
This will show a top line which contains the date, how long the systems
been running, how many users are on and whats called the >load average?
which is how many processes are contending for the (+). This is shown
as three numbers8 the first is for . minute ago, the second / minutes ago,
the third ./. ;ll you really need to know is that small numbers are good
;fter this w will show a header that says what the columns are for,
username, tty, when that user logged in, how long they've been idle, the
(+) and the +(+) and finally what the process is. (+) is the total (+)
time used by all the processes attached to that terminal, the +(+) time is
just for the current process running in the foreground. @uite often these two
numbers will be the same. Anowing exactly what these numbers mean or
how to use them isn't really essential knowledge, but can prove useful or
D) +i/pla> >o&$ "a.e i" 2o$. o2 a ,a""e$.
The ,a""e$ (ommand displays a large ;,(%% art version of input text. %t is
commonly included in )'%0 and )nix-like operating systems. There are two
common varieties8 one, which prints text horizontally for display to a
terminal, and another which prints text in much larger letters for output to a
line printer.
? ,a""e$ S#&%e"#
? ,a""e$ 5D0 a
). +i/pla> #1e "a.e o2 %e0ice "a.e o" >o&$ #e$.i"al.
To display the device name of the terminal, use the tty command8
The tty utility writes to the standard output the name of the terminal that is
open as standard input.
? ##>
10). Mo0e #o $oo# %i$ec#o$>.
To move to root directory use (1 command.
? c%
11). C1a"ge >o&$ %i$ec#o$> #o #1e %i$ec#o$> e(e$ci/e/. C$ea#e a 2ile
calle% e(a.ple1 &/i"g #1e ca# co..a"% co"#ai"i"g #1e 2ollo5i"g #e(#:
Bater, water everywhere
;nd all the boards did shrinkC
Bater, water everywhere,
'o drop to drink.
;ssuming that there is a directory called exercises,
To change to directory exercises from the current working directory, use the
(1 command8
? c% e(e$ci/e/
To c$ea#e a 2ile i" #1e %i$ec#o$> e(e$ci/e/:
? ca# E e(a.ple1.2
Fa#e$G 5a#e$ e0e$>51e$e
A"% all #1e ,oa$%/ %i% /1$i"=H
Fa#e$G 5a#e$ e0e$>51e$eG
No %$op #o %$i"=.
Be careful not to type ^D when you have the shell prompt, because this
might log you out.
12) '/e MAN co..a"% #o o,#ai" 2&$#1e$ i"2o$.a#io" o" #1e 2i"ge$
The man command displays information from the reference manuals. %t
displays complete manual pages that you select by name, or one-line
summaries selected either by keyword #-k$, or by the name of an
associated file #-f$. %f no manual page is located, man prints an error
? .a" co..a"% "a.e
? .a" 2i"ge$
Fi"ge$ - %i/pla> i"2o$.a#io" a,o&# local a"% $e.o#e &/e$/
13) Li/# all #1e p$oce//e/ #1a# a$e p$e/e"#l> $&""i"g.
To find out information about the processes running on the system use the
p/ command.
? p/
;nd you will see a list that probably just includes your shell #tcsh$. Bhile
this is fairly useful in and of itself you'll often find that you're logged in to two
or three TT"s at once doing various things, and so you'll need to find out
more than just the processes running on that login.
To see a list of all your running processes use8
? p/ -' J'SEK
This will show you information about your processes with much more
information including the )%1, +%1, ++%1, TT" and the command line and
all its arguments used to start the command.
%f you wanted to know this about another user you could simply use8
? p/ -2& &/e$"a.e
where >username? is the name of a user whose processes you want to see.
-astly if you want ps to show you information about all the processes
running on the system then you need to -e flag8
? p/ -e
2ost of time this isn't really needed, but sometimes you will want to be able
to find out information like this. %t should also be noted that the -e flag can
be combined with the -f flag, to show all the processes on the machine and
full information about them.
14) Li/# #e(# 2ile/ i" >o&$ c&$$e"# %i$ec#o$>.
To find and list text files in the all the directories, use the &%'1 command8
? 2i"% 41o.e -"a.e L<.#(#L -p$i"# 2E4%e04"&ll
will search all user directories for any file ending in :.txt: and output any
matching files #with a full absolute or relative path$. <ere the !uotes #:$ are
necessary to avoid filename expansion, while the DE3dev3null suppresses
error messages #arising from errors such as not being able to read the
contents of directories for which the user does not have the right
To find and list text files in the current directory ,tudent8
? 2i"% 4S#&%e"# -"a.e L<.#(#L -p$i"# 2E4%e04"&ll
;nother way to find and list text files in the current directory is to use the
-F(;TG command8
? loca#e L.#(#L
will find all filenames in the file system that contain :.txt: anywhere in their
full paths.
Fne disadvantage of locate is it stores all filenames on the system in an
index that is usually updated only once a day. This means locate will not
find files that have been created very recently. %t may also report filenames
as being present even though the file has just been deleted. )nlike find,
locate cannot track down files on the basis of their permissions, size and so
;nother option to find and list text files in the current directory is8
? l/ p 8 g$ep 0 M4N 2ile < 8 g$ep #e(#
? l/ -l <.#(# l/
1*) Ma=e a cop> o2 a"> #e(# 2ile.
To copy any text file to another text file use the cp command8
cp file1 file2 is the command which makes a copy of 2ile1 in the current
working directory and calls it 2ile2.
&irst (1 to your current directory8
? c% O4S#&%e"#
Then, copy the text file,
? cp 4&"i(4e(a.ple/4cop>.#(#.
#'ote8 1on't forget the dot #.$ at the end. Hemember, in )'%0, the dot
means the current directory.$
? cp 2ile1 2ile2.
1@) Ke"a.e o"e o2 >o&$ #e(# 2ile/ i" #1e c&$$e"# %i$ec#o$>.
To rename file in current directory use 2I move command8
? .0 2ile.#(# 2ile"a.e.#(# .0 P&"=.#(# "e52ile
1B) +ele#e a" &""ee%e% cop> o2 a 2ile.
To delete a file use the rm remove command8
? $. 2ile.#(#
1D) P$i"# o&# a"> 2ile o" pape$.
To print a file in )'%0 uses the lpr command8
? lp$ 2ile"a.e.#(#
lpr !ueues the specified file for printing. %f no file is specified, it reads
from the standard input. Fptions that may be specified include printer,
number of copies, processing and post-processing option.
The lpq program lists the job in the print !ueue.
The command lprm may be used to remove a print job from !ueue.
The command options include the printer and job-id or user-name. %f
the user-name is specified all jobs for that user will be de!ueued.
The command lpc is normally used interactively. %t allows the super-
user to start3stop the daemons, enable3disable !ueuing or printing
jobs, and monitor the status of a printer. The subcommand help prints
a short list of the commands that may be entered.
1) Se"% .e//age #o a"o#1e$ &/e$ o" >o&$ 'NI- />/#e.G a"% ge# #1e.
#o $epl>.
The mail command enables the user to send and receive electronic mail
messages to and from users on both the )nix system and remote users.
To send a message to a user on your system, type8
? .ail username
The cursor will move to the next line, and you will get a ,ubject8 prompt.
"ou can now type in the subject of your message, and then press
JHGT)H'E. The cursor will go to the start of the next line and there will be
no prompt. "ou now type in the text of your message. Terminate each line
with JHGT)H'E. Bhen you have finished the text of the message, type an
end-of-file character #usually K1$, or a full-stop character.
There are several commands you can type while entering mail8
QCTKL4RE will cancel the message, and leave the text in a file named
Ie invokes a text editor to edit your message.
O0 invokes a screen editor to edit your message.
O2 reads the contents of the message you have just read, into your
message text.
O$ file reads contents of file into your message text.
20) C$ea#e a /.all #e(# 2ile a"% /e"% i# #o a"o#1e$ &/e$.
To create a text file, use the cat command8
? ca# E S#&%e"#
To send this file to another user user .8
? .ail &/e$1 Q S#&%e"#
)se the re-direction to output stream operation.
21) F1e" >o& $ecei0e a .e//ageG /a0e i# #o a 2ile o#1e$ #1a" >o&$
)'%0 uses two mailboxes to hold mail messages
/>/#e. .ail,o( !4&/$4/pool4.ail4)
&/e$ .ail ,o( !....4...4.,o()
2ail arrives in the system mailbox, and is saved in your user mail box after
you have read it. The user mail box is normally located in their L<F2G
To save a current mail message to a file other than the default mailbox, use
the command save8
? / 2ile "a.e
Bhen the mail program starts, it uses the default mail folder, which is the
system mailbox. Hemember the save mail message command, which
saved the mail message to a file.
%t was stated that the mail program treats this file as a mail folder.
7y specifying the mail folder on the command line as an argument, mail will
use a different mail folder.
? .ail -2 pe$/o"al
22) Se"% a .e//age #o a &/e$ o" a %i22e$e"# co.p&#e$ />/#e..
,ending mail to users on other computer systems is simple using mail.
,imply type the full address of the remote user.
? .ail S#&%e"#Sig"o&.ac.i"
23) T$> #o .o0e #o #1e 1o.e %i$ec#o$> o2 /o.eo"e el/e i" >o&$ g$o&p.
T1e$e a$e /e0e$al 5a>/ #o %o #1i/G a"% >o& .a> 2i"% #1a# >o& a$e "o#
pe$.i##e% #o e"#e$ ce$#ai" %i$ec#o$ie/. See 51a# 2ile/ #1e> 1a0eG a"%
51a# #1e 2ile pe$.i//io"/ a$e.
To move to the home directory of someone else in the group8
? c% O &/e$1
To list the files in the directory and their permissions8
? l/ l%g
24) T$> #o cop> a 2ile 2$o. a"o#1e$ &/e$9/ %i$ec#o$> #o >o&$ o5".
7efore trying to copy the file, see the permissions that have been set for a
file, use the ls command with -l option
? l/ l
%f the Mr permission is set in the groupNs option of the permission set, and
then the file can be copied.
;ssuming Mr to be set,
To copy a file from another users directory to home directory of current
&irst locate the userNs directory.
? 2i"ge$ %i$ec#o$>1
Be learn that the user. directory is 3user.3directories3directory.
To copy file named file. from the user. directory, do8
? cp 4&/e$14%i$ec#o$ie/4%i$ec#o$>1 2ilecop>1
2*) Se# pe$.i//io"/ o" all o2 >o&$ 2ile/ a"% %i$ec#o$ie/ #o #1o/e #1a#
>o& 5a"#. To& .a> 5a"# #o gi0e $ea% pe$.i//io" o" /o.e o2 >o&$ 2ile/
a"% %i$ec#o$ie/ #o .e.,e$/ o2 >o&$ g$o&p.
To set permissions on files8
Gach file and directory has three kinds of permissions8
$ea% --E permission to view, print and copy --E abbreviated r
5$i#e --E permission to change the contents --E abbreviated w
e(ec&#e --E permission to run an executable file --E
#for example, a program$ FH
permission to change into a directory
abbreviated x
Bhen setting file3directory permissions, )nix divides the world of users into
three classes8
>o&G #1e o5"e$ --E abbreviated u
>o&$ g$o&p --E abbreviated g
o#1e$/ --E abbreviated o
"ou may assign read, write or execute permission independently to any of
the three classes of users.
)nix is not capable of permitting files and directories to individual users, but
#as explained below$ files and directories are usually permitted so that
others cannot access them without knowing their absolute pathnames.
Loo=i"g a# pe$.i//io"/
To see the permissions that have been set for a file, use the ls command
with -l option.
? l/ -l
-$5-$----- 1 S#&%e"# &/e$/ 21 U&l * 11:0D 2ile1
The first .O characters of the above line describe the type of the file and the
permissions which have been set for it.
The first character shows the file type. %t is -
#dash$ for a standard file and d for a directory.
The next 9 characters are actually P sets of P
characters each. These P sets show the
permissions for the owner, the group and others.
Bithin each set, permissions are always
described in the same order8 read #$$, write #5$
and execute #($. %f the relevant letter #r, w or x$
appears, permission exists. %f a - #dash$ appears
in its place, that kind of permission is denied.
-et's look at the permissions for another file8
%n this example, the owner may read the file,
write to it #change it$ and execute the file.
2embers of the group may read and execute
the file, but not write to it. Fther users may only
execute the file, not read it or write to it.
Gxecute access permits the execution of binary files which contain
executable programs. 7oth read and execute access are re!uired to
execute a shell script.
+e2a&l# pe$.i//io"/ 2o$ "e5 2ile/ a"% %i$ec#o$ie/
1efault permissions are automatically set for files and directories as you
create them. The default permission for new files is -rw------- and that for
new directories is drwx------.
C1a"gi"g 2ile pe$.i//io"/
The command chmod #short for c1ange .o%e$ is used to change
permissions for a file.
c1.o% g65 2ile1
This may be understood as follows8
Cla// Ac#io" Pe$.i//io"
u user
6 add permission r read
g *roup - remove
w write
o Fthers Q set permission x execute
a all
where class, action and permission can be chosen from the table of options
at the right above.
2ore than one class and more than one type of permission can be set at
the same time using chmod. &or example,
c1.o% &6(GoV$5 2ile1
adds the execute permission for the owner #u$ and sets the permission for
others to read and write explicitly #no matter what permissions others had
%f you do not specify a class, the new permission is applied to all three
classes. &or example,
c1.o% 6( 2ile
adds execute permission for the owner, group and others.
To change the permission of all files in a directory, use the wildcard symbol
:4:.&or example, the following command would add read permission for
others to all files in the current directory8
c1.o% o6$ <
'/i"g "&.e$ic a$g&.e"#/ 5i#1 c1.o%
%f you prefer, chmod can use a digit from O to R to represent the permissions
for each class of people. Gach digit is the sum of the permission values as
shown in the following chart8
Wal&e Pe$.i//io" E(pla"a#io"
S r read
D w write
. x execute
&or example, the command
c1.o% B*1 2ile1
would change the permission for file. to read, write and execute for the
ownerC read and execute for the groupC and execute only for others. Ialues
and the permissions they correspond to are shown below8
Wal&e Pe$.i//io" E(pla"a#io"
R Hwx read, write and execute
T rw- read and write
/ r-x read and execute
S r-- Head
P -wx write and execute
D -w- Brite
. --x Gxecute
O --- no access whatsoever
C1a"gi"g %i$ec#o$> pe$.i//io"/
To display the permissions for a directory, use the ls command with the -l
and -d options, giving the directory name as the argumentC e.g., for the
directory project.
? l/ -l% p$oPec#1
%$5(--(--( 2 S#&%e"# &/e$/ *12 U&l 3 11:2@ .
To display the permissions for your current directory, use the -l and -d
options on the ls command8
? l/ -l%
%$5(--(--( 11 S#&%e"# &/e$/ *12 U&l D 14:*4 .
-ike files, permissions for directories are changed using the chmod
command. Gither class and action abbreviations #e.g., chmod g6x$ or
numeric arguments #e.g., chmod TSS$ may be used to change directory
1irectory permissions have slightly different meanings than permissions for
files. Head #r$ permission is needed to list the contents of a directory with
the ls command. Brite #w$ permission means that files can be added to or
removed from the directory. Gxecute #x$ permission is needed before you
can change into a directory with the cd command or pass through a
directory as part of a search path.
F1e" >o& pe$.i# a 2ileG >o& 5ill al/o "ee% #o gi0e e(ec&#e pe$.i//io"
#o ,o#1 >o&$ 1o.e %i$ec#o$> a"% a"> /&,%i$ec#o$ie/ ,e#5ee" >o&$
1o.e %i$ec#o$> a"% #1e 2ile. Bhen you do this, other users will not be able
to list the contents of these directories, but they will be able to read or copy
the file as long as they know the absolute pathname.
&or example, user ,tudent wants to give others permission to read and
copy his file outline in subdirectory project. in his home directory. To do
this, he would type the following commands8
chmod oQx 3home3,tudent
chmod oQx 3home3,tudent3project.
chmod oQr 3home3,tudent3project.3outline
,ince execute permission does not allow others to see the contents of his
directories, ,tudent must tell his colleagues the absolute pathname of the
file, which is
2@) C$ea#e a "&.,e$ o2 1ie$a$c1icall> $ela#e% %i$ec#o$ie/ a"% "a0iga#e
#1$o&g1 #1e" &/i"g a co.,i"a#io" o2 a,/ol&#e pa#1"a.e/ !/#a$#i"g
5i#1 X4Y) a"% $ela#i0e pa#1"a.e/.
To create hierarchically related directories, use the 2A1%H command,
? .=%i$ 4S#&%e"#4S&,%i$ec#o$>1
? .=%i$ 4S#&%e"#4S&,%i$ec#o$>2
? .=%i$ 4S#&%e"#4S&,%i$ec#o$>3
To list the contents of the current directory, use the command8
= ls Mr
-a list hidden files
-c list file names in multiple-column format
To navigate through the directories using absolute pathnames8
&irst determine the current directory using the pwd#print working directory$
? p5%
Bithin our home directory #,tudent$, there are several files and a
subdirectory which also contains files #see diagram$8
Bithin our home directory #,tudent$, there are several files and a
subdirectory which also contains files #see diagram$8
%t is possible that more than one person could have a file called
bibliography. <ow does )nix distinguish
between files with the same nameU The full name of each file includes the
:path: through the directory hierarchy to that file.
The full names of two different bibliography files might be8
? 41o.e4S#&%e"#4p$oPec#14,i,liog$ap1> a"%
? 41o.e4Ig"o&4#1e/i/4,i,liog$ap1>
The names of the two bibliography files shown above are absolute
pathnames. ;n absolute pathname starts with a 3 to represent the root
directory, then traces the path through various subdirectories to the file.
;nother way to describe a file is by its relative pathname. Helative
pathnames do not begin with a 3. ; relative pathname shows how to get to
the file from the current working directory. %f we are in the directory ,tudent,
the relative pathname to our file bibliography is
? p$oPec#14,i,liog$ap1>
To navigate use the (1 command8
%f you are in the directory data, and wish to :back up: one level to the
directory chapterD #the parent of directory data$, you could type
c% c1ap#e$2
but a faster way is to use the abbreviation for parent directory #..$. There is
no space between the D periods.
c% ..
;nother useful abbreviation is V #called tilde$. This refers to the user's home
directory #,tudent in our example$. The easiest way to change back to your
home directory from any directory is to type
c% O
; third abbreviation #.$ means the current working directory. &or example,
assume that we are in the directory data, and wish to copy the file
bibliography from the directory project. into the directory data. Bithout
using any abbreviations, we would need to type #all on one line$8
cp 41o.e4S#&%e"#4p$oPec#14,i,liog$ap1>
)sing the abbreviation for our home directory #V$ and the abbreviation for
the current working directory #.$ we would type only8
cp O4p$oPec#14,i,liog$ap1> .
2B) T$> &/i"g 5il%ca$%/ !X<Y a"% po//i,l> XZY).

)'%0 allows you to use wildcards #more formally known as metacharacters$
to stand for one or more characters in a filename.
The two basic wildcard characters are U and 4. The wildcard U 2atches any
one character. The wildcard 4 matches any grouping of zero or more
;ssume that your directory contains the following files8
(hap bite
(hapT it
-it site
big snit
bin test.new
bin.old test.old
T1e Z 5il%ca$%
The command ls will list all the files. The command
l/ Zi#

Li# ,i#
lists only the files -it and bit. The file snit was not listed because it has two
characters before :it:. The file it was not listed because it has no characters
before :it:.
The U wildcard may be used more than once in a command. &or example,
l/ ZiZ

Li# ,ig ,i" ,i#
finds any files with :i: in the middle, one character before and one character
T1e < 5il%ca$%
The 4 wildcard is more general. %t matches zero or any number of
characters, except that it will not match a period that is the first character of
a name.
l/ <i#

Li# ,i# i# /"i#
)sing this wildcard finds all the files with :it: as the last two characters of
the name #although it would not have found a file called .bit$.
Be could use this wildcard to remove all files in the directory whose names
begin with :test:. The command to do this is
$. #e/#<
7e careful when using the 4 wildcard, especially with the rm command. %f
you had mistyped this command by adding a space between test and 4,
)nix would look first for a file called test, remove it if found, and then
proceed to remove all the files in the directoryW
Ma#c1i"g a $a"ge o2 c1a$ac#e$/ 5i#1 [ \
The U wildcard matches any one character. To restrict the matching to a
particular character or range of characters, use s!uare brackets X Y to
include a list. &or example, to list files ending in :ite:, and beginning with
only :a:, :b:, :c:, or :d: we would use the command8
l/ [a,c%\i#e
This would list the file bite, but not the file site. 'ote that the se!uence X Y
matches only one character. %f we had a file called delite, the above
command would not have matched it.
"ou can also specify a range of characters using X Y. &or instance, X.-PY will
match the digits ., D and P, whileX;-ZY matches all capital letters.
l/ [A-R\i#
will find any file ending in :it: and beginning with a capital letter #in this
case, the file -it$.
Bildcards can also be combined with X Y se!uences. To list any file
beginning with a capital letter, we would use8
l/ [A-R\<

C1ap1 C1ap@ Li#
Ma#c1i"g a /#$i"g o2 c1a$ac#e$/ 5i#1 ] ^
The method described in the previous section matches a single character
or range of characters. %t is also possible to match a particular string by
enclosing the string in [ \ #braces$. &or example, to list only the files ending
in the string :old:, we would use
l/ <]ol%^

,i".ol% #e/#.ol%
To list all files ending in either :old: or :new:, use
l/ <]ol%G"e5^

,i".ol% #e/#."e5 #e/#.ol%
2D) P&# a li/# o2 #1e 2ile/ i" >o&$ %i$ec#o$> i"#o a 2ile calle% 2ileli/#. !#1e"
%ele#e i#;)
)sing the (+ command,
? cp OS#&%e"#4%i$ec#o$>1< 2ileli/#
? $. 2ileli/#
2) C$ea#e a #e(# 2ile co"#ai"i"g a /.all /#o$>G a"% #1e" &/e #1e /pell
p$og$a. #o c1ec= #1e /pelli"g o2 #1e 5o$%/ i" #1e 2ile.

To c$ea#e a 2ile 5i#1 a /1o$# /#o$>:
? ca# E /#o$>
The method described in the previous section matches a single
character or range of characters. %t is also possible to match a
particular string by enclosing the string in [ \ #braces$. &or
example, to list only the files ending in the string :old:, we would
To perform ,pell (heck8
? /pell /#o$>
30) Ke%i$ec# #1e o&#p&# o2 #1e /pell p$og$a. #o #1e 2ile calle% e$$o$/.
= spell story E errors
31) T>pe #1e co..a"% l/ l a"% e(a.i"e #1e 2o$.a# o2 #1e o&#p&#.
Pipe #1e o&#p&# o2 #1e co..a"% l/ l #o #1e 5o$% co&"# p$og$a. 5cG
#o o,#ai" a co&"# o2 #1e "&.,e$ o2 2ile/ i" >o&$ %i$ec#o$>.
The B( command is used to print the number of lines, words, and
characters in a file. S>"#a(: 5c [op#io"/\ 2ile"a.e
To find the number of files in a directory, enter
? l/ -l 8 5c l
l/ l : &or a long listing that shows file protections, size, and date
32) '/e c&# #o /#$ip a5a> #1e $e2e$e"ce .a#e$ial a"% lea0e P&/# #1e #e(#
(ut command is typically used to extract a certain range of characters from
a line, usually from a file.
S>"#a(: ? c&# [-,\ [-c\ [-2 li/#\ [-"\ [-% %eli.\ [-/\ [2ile\
7ytesC a list following -b specifies a range of bytes which will be returned,
e.g. &lags which may be used include
cut -b.-TT would return the first TT bytes of a line. '7 %f used in
conjunction with -n, no multi-byte characters will be split. ''7. -b will
only work on input lines of less than .ODP bytes
(haractersC a list following -c specifies a range of characters which
will be returned, e.g. cut -c.-TT would return the first TT characters of
a line
,pecifies a field list, separated by a delimiter
; comma separated or blank separated list of integer denoted fields,
incrementally ordered. The - indicator may be supplied as shorthand
to allow inclusion of ranges of fields e.g. !" for ranges SMT or #! as
shorthand for field / to the end, etc.
)sed in combination with -b suppresses splits of multi-byte characters
1elimiterC the character immediately following the -d option is the field
delimiter for use in conjunction with the -f optionC the default delimiter
is tab. ,pace and other characters with special meanings within the
context of the shell in use must be en!uoted or escaped as
)sed to bypass lines, which contain no field delimiters when -f is
specified, unless otherwise indicated.
The file used #and accompanying path if necessary$ to process as
input. %f no file is specified then standard input will be used
33) '/e #$ #o /#$ip a5a> a"> #ag/ #1a# a$e ac#&all> i" #1e #e(#!e.g.G
a##ac1e% #o #1e 5o$%/)G /o #1a# >o& a$e le2# 5i#1 P&/# #1e 5o$%/.
The tr command #translate characters$ is one of the true )nix filters. %t
copies its standard input to its standard output, while replacing the first
character specified on the command line with the second character
-etNs consider the text file to be example..txt,
J ec1o QBEQ4BE #1i/ i/ #1e #ag 2o$ ,ol% #e(#
Ca# e(a.ple1.#(# 8 #$ MQa-7EN Ma-7N
O&#p&#: B4B #1i/ i/ #1e #ag 2o$ ,ol% #e(#
34) Se# a 2ile #o ,e $ea%-o"l> 5i#1 #1e c1.o% !2$o. c1a"ge .o%e)
co..a"%. I"#e$p$e# #1e 2ile pe$.i//io"/ %i/pla>e% ,> #1e l/ l
(onsider file. to be present,
To set the file to be read-only to all,
? c1.o% a6$ 2ile1
To see the permissions of the file, use the ls Ml command. To see the
permissions of the entire directory use the ls Mld command.
3*) +ele#e o"e o$ .o$e %i$ec#o$ie/ 5i#1 #1e $.%i$ co..a"%. See 51a#
1appe"/ i2 #1e %i$ec#o$> i/ "o# e.p#>. E(pe$i.e"# !ca$e2&ll>;;) 5i#1 #1e
$. $ co..a"% #o %ele#e #1e %i$ec#o$> a"% i#/ co"#e"#.
&irst letNs go to home directory of user ,tudent8 cd V,tudent
-et us create a directory 3,tudent31irectoryD
? .=%i$ 4S#&%e"#4+i$ec#o$>2
%f the 1irectory D is not empty, then we get an error message8
+i$ec#o$>2: +i$ec#o$> "o# e.p#>.
To remove the directory and all its files and contents8
?$. $ +i$ec#o$>2
3@) E(pe$i.e"# 5i#1 #1e $e-%i$ec#i"g co..a"% o&#p&# !e.g.G l/ l E
2ile1). T$> XEEY i"/#ea% o2 XEY 5i#1 a" e(i/#i"g #e(# 2ile a/ #1e o&#p&#.
To :redirect: output -- to take what the system would have displayed on the
screen and put it in a file instead.
Fn issuing the ls Ml command, we can redirect the output to file., as8
? l/ l E2ile1
Bhen you redirect output to a file that already exists, any previous contents
are deleted before the command is completed. To prevent the accidental
overwriting of files, first issue the command8
/e# "oclo,,e$
then use = ls Ml E file.
%f file. already exists then we will get an error8
&ile.8 file exists.
<owever, if you are certain you want to replace the contents of an existing
file with redirected output, use the emphatic form of the redirection
? l/ E;2ile1
%t is possible to append the redirected output onto the end of an existing file,
instead of replacing the contents, by using the append symbol #EE$. The
following command adds the date to the end of the file file., without
removing its original contents8
%a#e EE 2ile1
%f you have issued the set noclobber command to prevent accidental
overwriting, you must use the emphatic form8
%a#e EE; File1
3B) See 51e#1e$ &ppe$-ca/e 0e$/io"/ o2 a"> o2 #1e/e co..a"%/ 5ill
5o$= a/ 5ell a/ #1e lo5e$-ca/e 0e$/io"/.
'NI- i/ <ALFATS< ca/e-/e"/i#i0e.
%f you want to list your files with the ]ls' command, if you enter -, you will
be told :command not found.:
3D) '/e #1e 51o co..a"% #o /ee &/e$/ logge% i"#o #1e />/#e..

? 51o lists all users currently logged into the system. if you want to list
your files with the ]ls' command, if you enter -, you will be told :command
not found.:
The general format for output is8
name XstateY line time XidleY XpidY XcommentY Xe$itY
name )ser's login name
state (apability of writing to the terminal
line 'ame of the line found in 3dev
time Time since user's login
idle Time elapsed since the user's last activity
pid )ser's process id
(omment line in i"i##a, !4)
e$it Gxit status for dead processes
3) Pipe #1e o&#p&# o2 #1e 51o co..a"% #o #1e /o$# co..a"%.
)'%0 /o$# command to sort data
either alphabetically or numerically #-" option$
in ascending or descending order #-$ -- sort in reverse option$
By default sort sorts the file in ascending order using the entire line
as a sorting key.
The /o$# command can be used in pipes or have its output redirected as
To pipe the output of the 51o command to the input of the /o$# command8
?51o 8 /o$# E2ile1

40) Sea$c1 2o$ >o&$ logi" "a.e i" 51o2ile !2ile1) &/i"g #1e g$ep
The g$ep command search for the pattern specified by the +attern
parameter and writes each matching line to standard output. The g$ep
command displays the name of the file containing the matched line if you
specify more than one name in the %ile parameter. (haracters with special
meaning to the shell #L, 4, X, ^, K, #,$, _$ must be in !uotation marks when they
appear in the &attern parameter.
To find a word within some text, display all lines matching :pattern.:,
g$ep pattern1 2ile
? 51o 8 g$ep S#&%e"#
41) Co.pa$e #5o #e(# 2ile/ 5i#1 #1e %i22 co..a"%.
The diff command is used to display two files and prints the lines that are
different. %t prints a message that uses ed-like notation #a for append, c for
change, and d for delete$ to describe how a set of lines has changed. This
is followed by the lines themselves. The J character precedes lines from
the first file and E precedes lines from the second file. The diff command
displays the only line that differs between the two files.
-et's create an example to explain the output produced by diff. -ook at the
contents of three sample files8
#e/#1 #e/#2 #e/#3
apples apples oranges
oranges oranges walnuts
walnuts grapes chestnuts
Bhen you run diff on test1 and test2, the following output is produced8
L %i22 #e/#1 #e/#2
Q 5al"&#/
E g$ape/
42) Co&"# #1e "&.,e$ o2 li"e/ 5o$%/ a"% c1a$ac#e$/ i" a 2ile 5i#1 a 5c
The :wc: command stands for :word count:. %t counts the number of
characters, words, and lines that are contained in a text stream.
5c 4e#c4pa//5%
This command tells you the number of characters, words, and lines in the
3etc3passwd file.
5c -l 4e#c4pa//5%
This command tells you the number of lines #only$ in the 3etc3passwd file.
5c -5 M>S#o$>
This command counts the number of words in the file named 2y,tory
#which can be useful if you're paid by the wordW$.
51o 8 5c -l
This command counts the number of users logged into your computer
system. The output of the who command is piped into the wc command,
which counts the number of lines in the who output.
p/ -e 8 5c -l
This command counts the number of processes running on your computer
43) +i/pla> >o& c&$$e"# e"0i$o".e"# 0a$ia,le/ 5i#1 #1e 2ollo5i"g
co..a"%: /e# o$ e"0.
,tandard )'%0 variables are split into two categories, environment
variables and shell variables. %n broad terms, shell variables apply only to
the current instance of the shell and are used to set short-term working
conditionsC environment variables have a farther reaching significance, and
those set at login are valid for the duration of the session. 7y convention,
environment variables have )++GH (;,G and shell variables have lower
case names.
G'I%HF'2G'T variables are set using the /e#e"0 command,
displayed using the p$i"#e"0 or e"0 commands, and unset using the
&"/e#e"0 command.
To show all values of these variables, type
? p$i"#e"0 8 le//
The current environment variable settings can be displayed using the
setenv command with no arguments.
To use an environment variable in a command, preface it with a dollar sign
#L$, for example L'()*. This tells the command interpreter that you want
the variable's value, not its name, to be used. "ou can also use L['()*+,
which avoids confusion when concatenated with text
44) Co"ca#e"a#e all 2ile/ i" a %i$ec#o$> $e%i$ec#e% #o 4%e04"&ll a"%
$e%i$ec#i"g /#a"%a$% e$$o$ #o Xe$$o$ 2ileY.
To concatenate files in )nix use the cat command.
? ca# <E 4%e04"&ll4e$$o$2ile
4 ;ll files in directory.
4*) +i/pla> i"2o$.a#io" o" c&$$e"# &/e$ o$ o#1e$ &/e$ &/i"g 2i"ge$
The 2i"ge$ displays information about the system users.
,yntax8 2i"ge$ X-l./pY
-s8 Fi"ge$ displays the user's login name, real name, terminal name
and write status #as a ''4'' after the terminal name if write per-
mission is denied$, idle time, login time, office location and
office phone number.
-l8 Fi"ge$ displays the user's login name, real name, terminal name
and write status #as a ''4'' after the terminal name if write per-
mission is denied$, idle time, login time, office location and
office phone number.
-p8 +revents the -l option of 2i"ge$ from displaying the contents of
the :.plan:, :.pro,ect: and :.pgpkey: files.
-m8 +revent matching of user names.
V3.nofinger %f finger finds this file in a user's home directory,
it will, for finger re!uests originating outside the
local host, firmly deny the existence of that user.
&or this to work, the finger program,must be able to
see the .nofinger file.
This generally means that the home directory containing
the file must have the other-users-execute bit set #o6x$.
= finger Ms
To see other users8 = finger username`domain
To see details in less3more than one page = finger
username`domain ^less3more
4@) I2 >o& 5i/1G e(pe$i.e"# 5i#1 #1e /e"%i"g a"% $ecei0i"g .ail &/i"g
#1e pi"e e.ail p$og$a..
+ine is an easy to use, character based mail client. %t supports full screen
editing of messages, binary attachments #such as *%& or Z%+ files$, and
other advanced message system features that were not possible using
older electronic mail clients.
&eatures of pine8
&ull ,creen (apabilities
,afety for 'ew )sers M confirmation of actions.
Fn--ine <elp
Se"%i"g A##ac1.e"#/ 5i#1 To&$ Me//age MIME e"co%i"g
'ame Hecognition #;ddress 7ooks$
2essage 7rowsing
2essage +rinting
,aving 2essages
+ine is a menu based screen and you should look at the bottom of
the screen where valid menu commands are shown
)sing +%'G8
.. Type pi"e at the )'%0 prompt and you will see the pine screen.
D. Gnter user name and password.
P. To compose mail, )se the compose command C - COMPOSE
MESSAAE to compose a message. ;fter composing, to send the
mail, use C#$l6- to send your message. (an you see the choice I-
Se"% in the menu bar at the bottom of the screen.
S. To see the mails you have received use the L - LIST FOL+EKS
command from the main menu to see your folders and choose the
%'7F0 folder. )se N - Ne(#M/g to read the next message or P -
P$e0M/g to read previous message.
/. To reply use the K - Kepl> command, and to forward mail use the F -
Fo$5a$% command.
T. "ou can use the + - +ele#e command to delete your unwanted mails.
R. %f you want to print #or read the message you want to print, then
choose the command O - OTCEK CM+S, then choose command ? -
P$i"#. ;t the bottom you will see the message P$i"# .e//age n
&/i"g La##ac1e%-#o-a"/iL Z , where n is the message number.
;nswer it with T [Te/\ . ; pop-up print setup screen will appear, and
click O_ button. "our mail content will then be printed from your local
a. "ou can exit pine by using ` - `'IT command when you are in the
main menu.
4B) +ele#e all 2ile/ i" #1e c&$$e"# %i$ec#o$> 51o/e "a.e e"%/ i" X.,a=Y
The command rm is used to delete files from a directory. %t is used as8
X.=Y$. filename
Bhere filename can be in the current directory
To remove all the files with the .bak extension8
X.=Y$. <.,a=
To $e.o0e all 2ile/ 5i#1 #1e .,a= e(#e"/io"G 5i#1o&# a/=i"g 2o$
?$. -2 <.,a=
4D) +i/pla> li"e/ 10-14 o2 a"> 2ile 51ic1 co"#ai"/ 2* li"e/.
To display set of lines in )'%0 we use an Gx editor.
Gditors available on )nix include8
e% basic line editor
e( line editor
0i screen editor
e.ac/ screen editor
Gx is an enhanced and more friendly version of ed. Ii is a screen-based
version of ex.
The command ex is used to invoke the editor. The format of this command
= ex XfilenameY
The p command #for 'print'$ used to display lines in the file. The format of
this command is8
8Xline-rangeY p
%f no range is supplied the current line is displayed.
+ressing JHGT)H'E is e!uivalent to moving on to and displaying the next
line. Bith small files it is possible to display the entire file by pressing
JHGT)H'E until the end of the file is reached.
-ine Hanges
Hanges of lines that can be given to edit commands include8
;bsolute line number
T refers to line T
.,T refers to lines . to T
Helative line numbers
-D refers to D lines before the current line
6P refers to P lines after the current line
-D,6P refers to a range from D lines before the current line to P lines after
the current line
,pecial symbols
L refers to the last line in the file e.g. Lp to display last line, .,Lp to display
entire file
. refers to the current line e.g. .,Lp to display from the current line to the end
To display lines .O-.S of any file which contains D/ lines, do
= .O,.S p
4) Co&"# 1o5 .a"> li"e/ co"#ai" #1e 5o$% /cie"ce i" a 5o$% 2ile
&irst find the word using the grep command and then pie it using the wc
= grep science science.txt ^ wc Ml
*0) Li/# #1e /#a#i/#ic/ o2 #1e la$ge/# 2ile!o"l> #1e la$ge/# 2ile) i" #1e
c&$$e"# %i$ec#o$>.
Fne line script to find the largest file in the current directory is8
find . -type f -print ^ xargs ls -ladtr ^ cut -cPS- ^ sort -n -r ^ head J.E
a$ The above code should be executed in one line
#i.e. ignore word wrap$
b$ %nsert -xdev before the -print if you are
interested only in the filesystem you are in
and not others mounted under the directory
you are in.
*1) _ill a"> p$oce// 5i#1 1elp o2 #1e PI+ a"% $&" a"> p$oce// a# #1e
%n order to kill a process there are D ways8
&irst use ps to view what processes are running,
=ill pid where :pid: is the process %1 number listed under the +%1
column when you use p/.
,ometimes this doesn't work and you have to use a more aggressive
version of kill. =ill - pid will get the operating system to kill the
process immediately. This can be dangerous if the process has
control of a lock mechanisms, but your process will stop. %f you find
yourself completely stuck, terminals have frozen upon you and you
just don't know what to do, you can log in again and use =ill - -1.
This command will kill all of your processes including your current log
in. The next time you log in, everything that was running or was
locked up will have terminated.
To run the process in background8
,uspend the process using (trl6Z, This suspends execution of the
process, and gives you a command line.
To move the suspended process to the background, type ,g. The
process then resumes execution, exactly as if you had typed a when
starting the process.
To later bring a background process back into the foreground, use the
2g command. This command takes an argument specifying which
background process to place in the foreground. This is the job
number displayed when the process was placed in the background. %f
you cannot remember the job number of the process you wish to
bring back to the foreground, the Po,/ command will list all the jobs
you are currently running and their numbers.
)sing ps to view what processes are running, this will give you the following
OTR console OO8O/ sh
OTP ttyOD .O8DO 3bin3local3usr3zsh
OTD ttyOD .O8DD ps
OTO ttyOO .D8O/ 3net3pppd
To kill the process OTP
= Aill OTP
To move process OTO to background8
= bg OTO
*2) Selec# a #e(# File a"% %o&,le Space #1e li"e/.
)se the ,G1 command to double space the lines in a text file.
? /e% 2ile"a.e
*3) Li/# all &/e$/ 2$o. e#c4pa//5% i" #1e alp1a,e#icall> /o$#e% o$%e$.
To list all users on a )nix system, even the ones who are not logged in,
look at the 3etc3password file.
To see in detail, about all the users do8 L cat 3etc3passwd
to just see the )nix user names, use the command LJ ca# 4e#c4pa//5% 8
c&# -%: -218/o$#
*4) C$ea#e a 2ile 5i#1 %&plica#e $eco$%/ a"% %ele#e %&plica#e $eco$%/
2o$ #1a# 2ile.
To delete duplicate files8
Fn a single line #you can copy-paste this directly to a shell$8
F)T&Qrem-duplicates.shC echo :cW 3bin3sh: E LF)T&C find :L`: -type f
-printO ^ xargs -O -n. md/sum ^ sort --keyQ.,PD ^ uni! -w PD -d --all-
repeatedQseparate ^ sed -r 's3KXO-9a-fY4# $433Cs3#XKa-z;-ZO-9.3d-Y$3___.3gCs3#.
6$3crm _.3' EE LF)T&C chmod a6x LF)T&C ls -l LF)T&
S1ell Sc$ip# :
echo :cW 3bin3sh: E LF)T&C
find :L`: -type f -printO ^
xargs -O -n. md/sum ^
sort --keyQ.,PD ^ uni! -w PD -d --all-repeatedQseparate ^
sed -r 's3KXO-9a-fY4# $433Cs3#XKa-z;-ZO-9.3d-Y$3___.3gCs3#.6$3crm _.3' EE
chmod a6x LF)T&C ls -l LF)T&
.. write output script header
D. list all files recursively under current directory
P. escape all the potentially dangerous characters with xargs
S. calculate 21/ sums
/. find duplicate sums
T. strip off 21/ sums and leave only file names
R. escape strange characters from the filenames
a. write out commented-out delete commands
9. make the output script writable and l/ -l it
To create a duplicate copy of the file8
J cp 2ile"a.e1 2ile"a.e2
To remove the duplicate copy8
**) '/e #1e Xg$epY co..a"% #o /ea$c1 #1e 2ile e(a.ple1 2o$ #1e
occ&$a"ce/ o2 #1e /#$i"g X5a#e$Y
J g$ep 5a#e$ e(a.ple1
*@) F$i#e g$ep co..a"%/ #o %o #1e 2ollo5i"g ac#i0i#e/:
To select the lines from the file that has exactly two characters.
To select the lines from a file that start with upper case letters.
To select the lines from a file that has one or more blank spaces.
To select the lines from a file that end with a period.
To select the lines in a file and direct them to another file which has
digits as one of the characters in that line.
PAKT-I: MCS-043: +BMS La,
Ta,le C$ea#io":
!! .reate table
create table TG;(<GH
Td'F I;H(<;HD#P$ not null,
&d';2G I;H(<;HD#/O$,
-d';2G I;H(<;HD#D/$,
,;-;H" ')27GH,
,)+GHI%,%FH I;H(<;HD#P$,
F%'%'*1;TG 1;TG,
7%HT<1;TG 1;TG,
T%T-G I;H(<;HD#P$,
%'( ')27GH
tablespace ,",TG2
pctfree .O
pctused SO
initrans .
maxtrans D//
initial TSA
minextents .
maxextents unlimited
!! .reate/0ecreate primary, unique and foreign key constraints
alter table TG;(<GH
add constraint TG;(<GHd+A primary key #Td'F$
using index
tablespace ,",TG2
pctfree .O
initrans D
maxtrans D//
initial TSA
minextents .
maxextents unlimited
!! .reate table
create table (-;
(-;,,d'F I;H(<;HD#P$ not null,
Td'F I;H(<;HD#P$,
HFF2d'F I;H(<;HD#P$
tablespace ,",TG2
pctfree .O
pctused SO
initrans .
maxtrans D//
initial TSA
minextents .
maxextents unlimited
!! .reate/0ecreate primary, unique and foreign key constraints
alter table (-;,,
add constraint (-;,,d+A primary key #(-;,,d'F$
using index
tablespace ,",TG2
pctfree .O
initrans D
maxtrans D//
initial TSA
minextents .
maxextents unlimited
alter table (-;,,
add constraint (-;,,d&A foreign key #Td'F$
references TG;(<GH #Td'F$C
!! .reate table
create table +;",(;-G
2%'d-%2%T ')27GH,
2;0d-%2%T ')27GH,
*H;1G I;H(<;HD#/$ not null
tablespace ,",TG2
pctfree .O
pctused SO
initrans .
maxtrans D//
initial TSA
minextents .
maxextents unlimited
!! .reate/0ecreate primary, unique and foreign key constraints
alter table +;",(;-G
add constraint +;",(;-Gd+A primary key #*H;1G$
using index
tablespace ,",TG2
pctfree .O
initrans D
maxtrans D//
initial TSA
minextents .
maxextents unlimited
Table8 Teacher
tdno, fdname, ldname, salary, supervisor, joiningdate, birthdate, title
Table8 (lass
classdno, tdno, roomdno
Table8 +ayscale
mindlimit, maxdlimit, grade
E(e$ci/e 1:
,elect 4
from teacher
where birthdate Q #select max #birthdate$ from teacher$C
,elect 4
from teacher
where title Q #select title from teacher where upper#fdname$QN;%1GG+NC
,elect 4
from teacher
where joinddate E N.O-jul-.99/N
and salary in #select salary from teacher where joining date J N.O-jul-.99/NC
,elect t.4
from teacher t, payscale s
where t.salary between s.mindlimit
and s.maxdlimit
and s.grade Q N7NC
,elect t.4
from teacher t , payscale s
where exists #select 4 from class c where t.tdno Q c.tdno$
and #t.salary between s.mindlimit and s.maxdlimit$ and t.gradeQ(NC
,elect 4
from teacher
where supervisor QN"G,NC
h$ ,elect t.4, s.4
from teacher t, payscale s
where #t.salary between s.mindlimit and s.maxdlimit$
and #s.grade e(N or s.grade QN7N$ and #t.fdname like e=-=-=N$C
,elect t.4, c.4
from teacher t, class c
where t.tdnoQc.tdno
and c.classdno between . and /C
j$ ,elect 4
from teacher
where todchar#toddate#birthdate,N22N$$ Q todchar#toddate#sysdate,N22N$$C
E(e$ci/e 2:
(reate view supervisorddetails
select tdno, supervisior from teacherC
(reate index classdindex on class#tdno$ C
alter view supervisorddetails
select 4 from teacher where supervisiorQN"G,NC
select 4
from teacher
where todchar#joiningdate,'yyyy'$6./ E todchar#sysdate,'yyyy'$C
create T*T view
select 4 from teacher t where t.salary EQ.DOOO and t.titleQNT*TNC
drop view T*T C
create index teacherdindex on teacher#fdname$C
drop index classdindex C
create view teacherdinfo
select tdno, fdname, salary, grade
from teacher t, payscale s
where t.salary between s.mindlimit and s.maxdlimit and s.grade Q N7NC
j$ create view as select 4 from teacher where #todchar#toddate#birthdate,NyyyyN$$ -
todchar#toddate#system,NyyyyN$$$ E SOC
E(e$ci/e 3:
a$ create or replace procedure G0P;#T'F in out varcharD, bonus out float$
sal integerC

select salary into sal from teacher where tdno Q )++GH#tno$C

if sal E .OOOO then bonus 8Q sal 4 O..OC
elsif sal E.OOOO and sal JDOOOO then bonus 8Q sal 4 O.DOC
elsif sal EDOOOO and sal JD/OOO then bonus 8Q sal 4 O.D/C
elsif sal ED/OOO then bonus 8Q sal 4 O.POC
end ifC

end G0P;C
c$ create or replace procedure G0P(#result out varchar$
sal integerC
teacherdcount integerC
result 8Q ',)((G,,'C

select count#.$ into teacherdcount from teacher t where t.salary Q DOOOOC

cursor seldtea is select 4 from teacher t where t.salary Q DOOOOC
seldteadrec seldtea=rowtypeC

if not seldtea=isopen then
open seldteaC
end ifC

if teacherdcount JQ / then

fetch seldtea into seldteadrecC
exit when seldtea=notfoundC

update teacher
set inc Q seldteadrec.salary 4 O./O
where tdno Q seldteadrec.tdnoC

end loopC
end ifC
close seldteaC
end G0P(C