Documente Academic
Documente Profesional
Documente Cultură
Saumya Debray
Dept. of Computer Science
The University of Arizona, Tucson
debray@cs.arizona.edu
Reading
Chapter 1:
Upto Background
Jobs (page 17)
What is Unix?
Unix is an operating system
sits between the hardware and the
user/applications
provides high-level abstractions (e.g., files) and
services (e.g., multiprogramming)
Linux:
a Unix-like operating system: user-level
interface very similar to Unix
code base is different from original Unix code
users
applications
system
calls
shell
hardware
bb
cc
dd
ff
ee
Everything is a file
In Unix, everything looks like a file:
bb
cc
dd
ff
ee
gg
bb
cc
dd
ff
ee
absolute path:
/dd/ee/gg
gg
bb
cc
dd
ff
ee
gg
Example:
f relative to ee
is: ../f
bb
cc
dd
ff
ee
gg
10
Example:
cc relative to ee
is: ../../cc
bb
cc
dd
ff
ee
gg
11
Home directories
Each user has a home directory
specified when the account is created
given in the file /etc/passwd
Notational shorthand:
A shell is just
an interpreter
for Unix
commands
12
13
Processes
Programs are executed via processes
a process is the unit of execution
consists of:
the code that is executed
the data this code manipulates
Unix Commands
Each command performs [variations of] a
single task
options can be used to modify what a command does
different commands can be glued together to perform
more complex tasks
Syntax:
command
options
Command
Examples:
arguments
Options
pwd
cd
Options can
(usually) be
combined
together:
Arguments
these are
equivalent
/home/debray
ls
-a -l
ls
-al
/usr/local
15
Unix Commands
Each command performs [variations of] a
single task
options can be used to modify what a command does
different commands can be glued
to perform
Not together
always required:
more complex tasks
may have default
Syntax:
command
Command
Examples:
pwd
values
typical defaults:
options
arguments
input: stdin
output: stdout
Options
Arguments
directory: current
cd
/home/debray
ls
-a -l
ls
-al
/usr/local
defaults
to
current
director
y
16
cd ~
(also: just cd by itself)
cd
/usr/local/src
move to /usr/local/src
cd
../..
17
ls /usr/bin
ls -l
ls -a
ls -al /usr/local
18
Combining commands
The output of one command can be fed to
another command as input.
Syntax:
command1 | command2
pipe
Example:
ls
19
keyword
keyword
20
command
21
Example: man ls
22
23
we can specify
what kind of
information we
want
24
head n [file]
show the first n lines of the input
tail n [file]
show the last n lines of the input
cp file1 file2
copy file1 to file2
mv file1 file2
move file1 to file2
25
26
a lot fewer
results;
nothing
relevant
27
28
29
30
strongly
suggest
making this
your default
31
33
34
35
36
Example:
ls b*c
ls
a[xyz]*
ls *.pdf
37
I/O Redirection
Default input/output behavior for
commands:
stdin: keyboard; stdout: screen; stderr:
screen
We
cmd <
redirect cmds stdin to read from file
can
file change this using I/O redirection:
cmd >
file
cmd >>
file
cmd &>
file
cmd1 |
cmd2
39
owner
group
file name
access permissions
file type
normal file
directory
l
(ell)
symbolic link
40
read
w write
x execute
(executable file)
enter (directory)
no permission
41
Example:
chmod u-w
foo
chmod g+rx
bar
chmod o-rwx
*.doc
chmod a+rw
p*