Académique Documents
Professionnel Documents
Culture Documents
Introduction
(Bourne shell)
ksh (Korn shell)
csh (C shell)
tcsh
bash
Differences mostly in scripting details
Login scripts
You
tcsh
~/.login
~/.cshrc
'll'='ls -l'
'la'='ls -la'
'ls'='ls -F'
'rm'='rm -i'
'm'='more'
set -o vi
echo ".profile was read"
Programs
Redirecting stdout
Instead
Redirecting stderr
Instead
Examples
{ajax} ls j
ls: j: No such file or directory
{ajax} ls j >& hello.txt
{ajax} cat hello.txt
ls: j: No such file or directory
Redirecting stdin
Instead
Examples of filtering
ls
-la | more
cat file | wc
man ksh | grep history
ls -l | grep dkl | wc
who | sort > current_users
12
UNIX Tutorial
http://www.ee.surrey.ac.uk/Teaching/Unix/
Google
13
UNIX Filesystem
The
Everything
Working directory
The
15
Home directory
A special
files
When you log in, your working directory will
be set to your home directory
Your home directory is represented by the
symbol ~ (tilde)
The home directory of user1 is represented
by ~user1
16
Directories
may
contain plain files
or other
directories
Leads to a tree
structure for the
filesystem
Root directory: /
bin
dkl
foo.txt
bar.c
users
tmp
kangli
csci1730
abcd
17
Path names
Separate
directories by /
Absolute path
start at root and follow the
tree
e.g. /users/dkl/foo.txt
/
bin
users
dkl
foo.txt
tmp
kangli
csci1730
Relative path
bar.c
abcd
start at working directory
.. refers to level above; . refers to working dir.
If /users/dkl/csci1730 is working dir, all these
refer to the same file
../foo.txt
~/foo.txt
~dkl/foo.txt
18
Types of files
Plain
Most files
Includes binary and text files
Directory
(d)
Creating links
ln
s <curr_file> <link_name>
This command creates a symbolic link
The file link_name will be a pointer to the
curr_file which may be in another directory
or even on another physical machine
20
File permissions
Permissions
<filename(s)>
concatenate
output the contents of the file all at once
more
<filename(s)>
22
Heart of the OS
Process scheduling
I/O control (accesses)
Shell
Basic Commands(1)
ls
Basic Commands(2)
cp file1 file2
copy file1 and call it file2
mv file1 file2
move or rename file1 to file2
rm file
remove a file
rmdir directory
remove a directory
cat file
display a file
more file
display a file a page at a time
who
list users currently logged in
lpr -Pprinter psfile print postscript file to named printer
*
?
man
Basic Commands(3)
wc file
% wc -w science.txt
Unix
Identification and authentication
Passwords to authenticate
in /etc/passwd
-rwxrwxrwx
-rw-------
a file that only the owner can read and write - noone else can read or write and no-one has
execution rights (e.g. your mailbox file).
drwx-----lrwxrwxrwx
-rw-r--r--r-sr-xr-x
-r-sr-sr-x
2
1
1
1
1
jjoshi
jjoshi
jjoshi
root
root
isfac 512
isfac
15
isfac 1754
bin
9176
sys
2196
File type: regular -, directory d, symlink l, device b/c, socket s, fifo f/p
Permission: r, w, x, s or S (set.id), t (sticky)
Simple Unix
Directory Structure
/
usr
etc
home
grad
bin
ugrad ...
mmscott jpeckhar...
var ...
cat file
cat file1 file2 ...
cd directory1
cd /usr/bin
cd
clear
cp file1 file2
cp file1 file2 ... dir
ls
ls /usr/bin
more file
mkdir directory
mv file1 file2
mv file1 file2 ... dir
mv dir1 dir2
Starting Vi
Opening an existing file
vi filename
Vi Modes of Operation
Command Mode
Allows the entry of commands to manipulate text
Default mode when vi starts
Use Escape key to move into command mode
3. Use the :q! command to force quit without saving (Enter :q! ).
Saving Changes in vi
:wq Write/save changes and quite
:w Write/Save changes, but dont quit
1.
2.
3.
4.
5.
Vi Editor
How
1.
2.
3.
4.
5.
6.
7.
h key
move cursor to the left one
position
l key move cursor right one position
j key move cursor down one line
k key
cursor
up file.
one line
Type
vi mysongmove
to re-edit
your song
Use the l command several times to move cursor to the far right
Use the a command to move into append mode (Press a key).
Use the Enter key to start a new line of text.
Type: Artist: and then the name of the artist
Use the Esc key to move to command mode .
Practice moving cursor up, down, left,
and right with h,l,j,k keys.
Cutting text in Vi
d^
Deletes from current cursor position to the
beginning of the line
d$
Deletes from current cursor position to the
end of the line
Dw
Deletes from current cursor position to the
end of the word
dd
Deletes one line from current cursor position.
Specify count to delete many lines.
dd
Delete (cut) 1 line from current cursor
position
2dd Delete (cut) 2 lines (3dd to cut 2 lines,
1. Move etc.)
cursor to top line and type dd to cut the title line
2. Use the p command to paste the title line below the
p
paste lines below current line
artist line
3. Use the p command to paste it again.
Vi Editor
To go to a specific line in the file
:linenumber
1. Go to the 3rd line by typing :3
2. Go to the 1st line by typing :1
3. Go to the last line by typing G
Vi string/search
/[pattern] search forward for the pattern
?[pattern] search backward for the pattern
n
search for the next instance of a string
1. Search forward for the next line containing the string Title
by typing /Title
2. Search forward for the next instance of Title by typing n
3. Search backward for the most recent instance of Title by
typing ?Title
4. Search backward for the next most recent instance of Title
by typing n
More commands
yl
yank a single character. Specify count to yank more
characters
yw
yank a single word. Specify count to yank more
words
d^
Deletes from current cursor position to the beginning
of the line
d$
Deletes from current cursor position to the
end of the line
Dw
Deletes from current cursor position to the
end of the word