Professional Documents
Culture Documents
environment
use simple commands to manipulate files (cd, ls,
UNIX shell
Resources
On reserve in library: Your UNIX, The Ultimate
My notes
BSD UNIX
TCP/IP built-in
Applications
OS offers services:
Memory management
Access to hardware
UNIX Features
Multi-user
Multi-tasking
Threads
Virtual memory
Built-in networking
Kernel
User
ls
who
Hardware
cp
tar
ps grep
Browser
File System
"Files have places and processes have life"
Kaare Christian
both
Root: "/"
Shortcuts:
and password.
Usernames and passwords are case
sensitive!
Session Startup
Once you log in, your shell will be started
to type in a command.
The shell can deal with a couple of types of
$
commands:
shell internals - commands that the shell
%
handles directly.
External programs - the shell runs a program
&
for you.
Some Simple Commands
Here are some simple commands to get you
'
started:
lists file names (like DOS dir command).
* )
+
(
543
0
>
:
(eg., )
D C
E
@A
B
The command
The ls command displays the names of
F
some files.
+JI
H
working directory:
change directory
X
] \
E
e
a`_
^
^
Z
bc
d
With no parameter, the command
g
f
i
h
pathname: j
lm
k
j
n
n
Some more commands and
command line options
will list everything in a directory
q p
E
s
o
| {
E
| ~
}
}
z
|
z
The source is the name of the file you want
to copy.
dest is the name of the new file.
Deleting (removing) Files
The command deletes files:
E
¢
¡
£
£
£
stands for "remove".
¥¦
¤
« ª
¬
¯°
µ
©
5¶
¨©
±´
´
·
³
³
³
File attributes
Every file has some attributes:
¸
Access Times:
¹
Size
½
Permissions
¿
File System Security
Each file has three sets of permission bits:
À
user
Á
group
Â
other
Ã
read
Å
write
Æ
execute
Ç
File System Security
If a file's permission is "execute", is means it can
È
+ÐÏ
Ï
Ñ
Î
Ô Ó
+
Ö Ó
+
Õ
Ò
Ù Ø
+
Ø
Û
Ú
×
remove directory
ã
áâ
á
à
è
ä
terminal.
Shells
ð ï
+
î
Standard Input
ö
Standard Output
÷
Standard Error
ø
Programs and Standard I/O
Standard Error
(STDERR)
Unix Commands
Most Unix commands (programs):
ù
standard input.
What happens when you give the shell ^D?
Popular Shells
Bourne Shell
Korn Shell
C Shell
Bourne-Again Shell
Customization
Each shell supports some customization.
User prompt
Shortcuts
("
)
Wildcards (metacharacters) for
filename abbreviation
When you type in a command line the shell
0
specify filenames.
The shell processes what you give it, using
2
9
8
7
5
Try this:
F
DKJ
L
G
HI
M
DON DON DON DON
P R Q P
S P R
N
* and
P
Things to try:
Input Redirection
The shell can attach things other than your
T
file).
A pipe (the output of a program is fed as input
Y
to another program).
How to tell the shell to redirect
things
To tell the shell to store the output of your
Z
]\[
a
^
`_
the command above will create a file named
and put the output of the
]cb
]hg
f
ed
n
ij
k
po
q
i
m
• The command above would sort the lines
in the file nums and send the result to
stdout.
u
t
~ rs
v t
u
v
v
w w
| yx
u z
u| r
t {
{ rs
t
You can do both!
yt }|u
|
| yx
u z
|}u r
t
Input from file vs. from stdin
• UNIX commands can alternatively open a
file or read from stdin
–
–
£¢
¤§
¨
Asking for a pipe
Separate 2 commands with the “|”
©
character.
The shell does all the work!
ª
°
¬
®
«
«
¯
°
±
·¶
¬
³²
³´
µ
µ
«
«
¯
Pipes Examples
Count the files in a directory
% ls | wc -l
Show the 10 most recently modified files
% ls -lt | head
Search a file for all occurrence of the string "system"
and pause at each page
% cat file1.txt | grep "system" | more
We can combine these with redirections
% cat file1.txt | grep "system" >
output.txt
Shell Variables
The shell keeps track of a set of parameter
¸
a task.
Example Shell Variables
ÏÌ
ÐÑ
is saved
Displaying Shell Variables
Prefix the name of a shell variable with "$".
Ò
Ú
Û
Ø×
Ù
ÜÝ
Þ
Ú
Ø×
Ù
You can use these variables on any
ß
command line:
]áà
ãà
ä
å
â
Setting Shell Variables
You can change the value of a shell
æ
ïî
í
òñð
ì
ôóì
èç
éê
ë
ç
úû
úû
õö
÷
ñí
ì
èç
éê
ë
ù
ë
ýü
ù
ë
ç
ìó
ù
ü
ø
ý
ú
ú
ú
þ
ðÿ
ö
ì
èç
éê
ë
ñ
command (shell builtin)
in.
If not - tries to find a program whose name
-)
, +
&
$#
#
"
./
0
*
'
4
4
4
3
3
3
, +
5 3
3
3
3
3
#
6
*5
%
5
7
2
2
1
4
3
3
,
3
3
3;
:
#
9#
38
5
*
5
*5
2
<
3;
!
=
3
AB
>
FG
C
startup file ( )
KL
MN
I
J
Job Control
The shell allows you to manage jobs
O
suspend a job
R
kill a job
S
Background jobs
If you follow a command line with "&", the
T
(window).
Y X
Z
Y X
Z
c
X\
]
Y
_^
`
[
b
Listing jobs
The command jobs will list all background
d
jobs:
g f
Z
i h
Z
e
kj
i s
i s
z
onm
e
p
p
pr
vu
w
t
y
e
pressing ^Z (Ctrl-Z).
Suspend means the job is stopped, but not
}
dead.
The job will show up in the output.
Z
Z
~
^C (Ctrl-C).
It's gone...
Programming
Text editors
emacs, vi
Debuggers: gdb