Professional Documents
Culture Documents
1
Objectives
➲ What is Unix?
➲ Unix history.
➲ Architecture of Unix/Linux.
3
What is Unix?
A portable, multi-tasking and
multi-user operating system
➲ Portable: runs on many different hardware
architectures (Intel x86 and IA-64, Alpha,
MIPS, HP PA-RISC, PowerPC, IBM S/390,
SPARC, Motorola 680x0, etc.).
➲ Preemptive multi-tasking: several programs
can run at the same time (time slices,
interrupts, and task switching).
➲ Multi-user: many users can share the
computer system at the same time.
4
What is Unix?
Other Features
➲ Uses a simple, uniform file model which includes
devices and access to other services in a
flexible, hierarchical file system.
➲ Written in a high-level language (“C”) making it
easy to read, understand, change and port.
➲ The command prompt is a simple user process,
the Unix shell, which is also a convenient job
programming language.
➲ Includes support for regular expressions which
are convenient for complex searching.
5
Is LINUX really UNIX?
●
Well, yes and no:
●
Yes, because it has essentially the same look and
feel like any UNIX operating System.
●
Yes, because it offers the ability to run nearly any
program that runs on UNIX systems (through API
conventions such as POSIX, etc..).
●
No because the heart of the system (kernel) has a
lot of new features that go beyond the classical
design philosophy of UNIX kernels.
Unix History
7
Unix History
➲ 1969 Bell Labs withdraws from group.
* Ritchie, D.M. “The Evolution of the Unix Time-sharing System”, AT&T Bell Laboratories
Technical Journal, Oct. 1984, Vol 63, No.8, Part 2, pp. 1577-1594.
8
Unix History
➲ At the same time Ken
Thompson wrote a game
“space travel” in Fortran to
run on GECOS OS
(Honeywell 635).
➲ The spaceship was hard
to control and it was
expensive to run. He was
told to get the game off his
work computer.
9
Unix History
➲ Thompson ported the game to a little
used PDP-7 computer.
➲ Unics (later Unix) was born as a pun
on Multics.
10
Unix History
PDP-7
11
Unix History
➲ Dennis Ritchie
developed “B” . Then
wrote “C” a compiled
language.
➲ In 1973 entire OS
ported to “C”.
12
Linus Torvalds
14
Three Definitions of Linux
➲Linux Kernel: The very low-level software that manages
your computer hardware and provides a library (POSIX)
interface for user-level software. The Linux kernel runs on
many platforms (Intel x86 and IA-64, Alpha, MIPS, HP PA-
RISC, PowerPC, IBM S/390, SPARC, Motorola 680x0, etc.).
19
Architecture of Unix
Architecture of Unix
Unix file system
root (/)
bin usr
dev etc
var
home tmp bin
(users’ mail)
21
Typical Directories
➲ /: Root of the tree. Where it starts.
23
Typical Directories
➲ usr: Contains application programs
➲ lib: Contains libraries for programs
➲ proc: a pseudo-filesystem used as an
interface to kernel data structures.
24
File and Directory Name Rules
➲ Valid names can be made up of:
● Uppercase letters (A to Z).
● Lower case letters (a to z). Case sensitive!!!
● Numbers (0 to 9).
● Period (.), underscore (_), commas (,).
➲ Should not contain spaces or the following:
● & * \ | [ ] { } $ < > ( ) # ? ‘ “ ; ^ ! ~ %. Never /.
● You should avoid naming files or directories with
Unix commands.
25
File System Structure
➲ Unix stores a file's administrative
information (its physical location on
disk, permissions including ownership
and modification times) in an inode (i-
node or Index Node).
➲ The file name (link) is stored in the
contents of a directory entry. Deleting
a file consists of removing a link to the
inode (the inode itself is not deleted).
26
File System Structure
Data Recovery:
➲ When a file is deleted the number of
links to the inode is reduced by one.
➲ Note: an inode may have more than
one link (or name) --- see ln(1).
➲ If the number of links becomes zero,
the kernel may reuse the disk space
making recovery difficult. Magnetic
Force Microscopy (MFM) can recover
most data unless wipe(1) is used.
27
The K Desktop Environment (KDE)
GNOME
OpenLook Windows Manager (olwm)
30
Common Desktop Environment (CDE)
31
How Do You Boot Unix?
Multi-boot Programs
➲ Windows NT OS loader- select the OS of
choice
32
Shell
ls -l /etc
➲ cp <fromfile> <tofile>
● Copy from the <fromfile> to the <tofile>
➲ mv <fromfile> <tofile>
● Move/rename the <fromfile> to the <tofile>
➲ rm <file>
● Remove the file named <file>
➲ mkdir <newdir>
● Make a new directory called <newdir>
➲ rmdir <dir>
● Remove an (empty) directory
More Commands
➲ who
● List who is currently logged on to the system
➲ whoami
● Report what user you are logged on as
➲ ps
● List your processes on the system
➲ ps aux
● List all the processes on the system
➲ echo “A string to be echoed”
● Echo a string (or list of arguments) to the terminal
More Commands
This finds all files in the current and subsequent directories with an extension of c,v. sed then
strips the ,v off the results of the find command. xargs then uses the results of sed and builds a
grep command which searches for occurrences of the word PATH in the C source files.
Pipes
An important early development in Unix was the
invention of "pipes," a way to pass the output of
one tool to the input of another.
eg. $ who | wc −l
By combining these two tools, giving the wc
command the output of who, you can build a new
command to list the number of users currently on
the system
Basic Unix commands (vs. DOS)
➲ cat file Concatenate or type out a file,
cat file1 file2 ... Type out a number of files
➲ cd directory1 Change current directory to directory1
cd /usr/bin Change current directory to /usr/bin
cd Change back to your home directory
➲ clear Clear the current screen
➲ cp file1 file2 Copy file1 to file2
cp file1 file2 ... dirCopy a number of files to a directory
➲ ls List the files in the current directory
ls /usr/bin List the files in the /usr/bin directory
➲ lpr file1 Print file1 out , lpr file1 file2 .. Print a number of files out
➲ more file Look at the content of a file with paging, use ‘q’ to get out
Basic Unix commands (vs. DOS)
➲ Navigation
● Left - h
● Down -j
● Up - k
● Right -l
● Top of the screen – H (shift + h) //caps lock will not work
● Middle of the screen – M (shift + m)
● Bottom of the screen – L (shift + l)
● $ - End Key, 0 – Home Key
➲ Edit Commands
● Cut – X, x
● Copy – yy, yw
● Paste – P, p
Vi editor
dd – Deletes a line
Shell Scripts
➲ To Print a line
● echo “Hello World” (Prints Hello World in the screen)
➲ To read a line
● read n (Stores the content entered by user in variable
n
➲ To Comment a line
● # This is a comment
● Only single line comment is available. For multi line
comment, we need to use # symbol in lines which we
want to comment.
Conditions
➲ We can have if, if else, if elif else and case statements (Nested if
statements are also possible
1. if [ condn ]
then
fi
2. if [ condn ]
then
else
fi
3. if [ condn ]
then
elif [ condn ]
then
else
fi
Conditions (Case)
case expr in
Option1) stmt ;;
Option2) stmt ;;
*) stmt ;;
esac
➲ Every option should be terminated with a
double semicolon.
➲ Denotes default case
➲ Case should be termniated with esac
Loops
➲ For loop
for i in 1 2 3 4 5 //Loops 5 times
do
Body of the loop
done
while [ condn ]
do
body of the loop
done
➲ Local Function
● Written at the command prompt
● Lasts for the current session alone
➲ Global Function
● Written in .bashrc file
● Available as long as the definition is there
in .bashrc file
➲ Function in shell script
● Available with in the file alone
Parameters
➲ Sample function
Functionname()
{
echo $1
}
Calling function:
Functionname Ram
Result:
Ram
We can pass any number of parameters like this
$0 – File name
$1,$2… - first, second parameters and so on
$? – stores the status (success or failure status of the last command that was
executed)
$# - stores the number of parameters passed through the command line
#pwd
/home
#echo $?
0 // As the last command is success
#abc
Error:command not found
#echo $?
127 // as the last command didn’t execute successfully
C Program in Linux
➲ Open a file with extension .c from the command prompt using vi
editor
● vi hello.c