Professional Documents
Culture Documents
What is UNIX?
continued
free! (LINUX, FreeBSD, GNU)
popular
profitable
1996 Sales: US$34.5 Billion, up 12%
not tied to one company
active community
Your Account
Each user has their own space called their
account.
or
^D Press CONTROL and D
together
or
exit
On-line Help
er
ti o
s
a
U m
ic
U
pl
ni m
ll
Co
U
e
x an
Ap
Sh
s
S
er
r
he are
h e
t
ll
O ftw
ds
So
Hardware
To ernet
Da cka
Pa
tab ges
ols
Int
as
e
Kernel
Sh
el
l Compilers
e ll
h
U
S
se
e r
r
Us
The Shell
display
prompt
read execute
command the shell command
process
command
Typing Commands
Try these:
date
cal 3 2005
who
ls -a
man cal
clear
Changing your Password
The command is:
passwd
cal Calendar
cal 1997
cal 3
cal 7 1962
cal 9 1752
You and the System
uptime Machine’s ‘up’ time
hostname Name of the machine
bc Programmable
Calculator
Some General Purpose Commands
date locate
cal more
who passwd
ls echo
man banner
clear tty
uptime uname
hostname tput
quota spell
whoami ispell
apropos cat
whatis sort
which pwd
Redirection, pipes , processes
Output can be redirected to a file with‘>‘:
ls > dir.txt
cal 2004 > year2004
Output can be appended to a file with ‘>>‘
cal 2004 > years
cal 2005 >> years
Pipes : sending the output of one program to
the input of the other
ls | sort
who | sort
Processes : Running two commands
sequentially
locate mj > xxx; date
locate usr > xxx &
The UNIX File System
The File
Ordinary Files
Directory Files
Device Files
The Parent Child Relationship
mj
Some System Directories
/ root directory
/bin commands
For example:
/usr/games/fortune
cat /etc/passwd List the password file
Moving between Directories
s3910120’s home directory:
s3910120
proj1 proj2
hobby.c
... ...
If you are in directory s3910120 how do
you move to directory proj1?
cd proj1
that
machine
finger @catsix
finger @ratree.psu.ac.th
mail Add
Chmod +x nuls
Example
if grep “professor” employee.list
then echo “record found”
else echo “record not found”
fi
Exploring the Shell Operator meaning
-eq =
-ne !=
Numeric comparison -gt >
test $x –eq $y -ge >=
-lt <
if test $# -eq 0 -le <=
then echo "no input argument"
else echo $1 Test True if
fi
-n stg stg is not a null
String Comparison string
if [ -z "$1" ]; -z stg stg is a null string
then echo "no input argument"
else echo $1
s1 = s2 s1 = s2
fi s1 != s2 s1 != s2
pattern9) Commands ;;
esac
Exploring the Shell
Computation
expr 3 + 5
expr $x + $y
Command Termination
P1 ; P2 - does P1 then P2
P1 & P2 - does P1 then P2 but does not wait
for P1 to finish.
Exploring the Shell
Looping while true ;
while (condition is true) do
do
date
commands
done sleep 100;
Looping with a list done &
for var in list for file in *.c
do do
commands cc –o $file{x} $file
done
done
Filters
The UNIX programs that read some input,
perform a simple transformation on it and
write some output.
Some option
-c Counting number of occurrences
-n Line numbers along with lines
grep Mamata –e mamata database
grep [Mm]amata database
grep : Regular Expressions
Character sets
[mM] , [aeiou] , [a-zA-Z0-9]
Immediately preceeding character
G*, [gG]*
Matching a single character
2… A four character pattern starting with 2
.* A number of characters or none
grep : RE c Any non-special character
c matches
\c Turn off any special
meaning of character c
^ Beginning of line
Specifying pattern
boundaries $ End of line
^r pattern beginning
with expression r . Any single character