UNIX AND SHELL SCRIPTING
MODULE-01
Introduction of UNIX
UNIX, the Operating System is found on virtually all Computer hardware in use today.
To the casual user, UNIX is simple and easy to use. To the experienced user, it is
powerful with a certain elegance that makes it extremely popular.
It supports the execution of multiple tasks or processes simultaneously.
It is widely known for its reliability, structured design, and long-term stability.
Its design principles have influenced many modern systems such as Linux, BSD, and
macOS.
FEATURES OF UNIX SYSTEM
1. PORTABLE: UNIX is found on more hardware platforms than any other operating
systems ever developed. Its widespread use can be directly traced to the decision to
develop it using the C language
2. MULTIUSER: The UNIX design allows multiple users to concurrently share hardware
and software. The UNIX resource –sharing algorithms allow to share the resources while
at the same time preventing any one user from locking out others.
3. MULTITASKING: Multitasking is an operating system feature that allows a user to run
more than one at a time. More than one program can be running in the background while
a user is working in the foreground.
4. ORGANIZED FILE SYSTEM: UNIX has a very organized file and directory system
that allows users to organize and maintain files.
5. DEVICE INDEPENDENCE: UNIX treats input/output devices like ordinary files. The
source or destination for the file input and output is easily controlled through a UNIX
design feature known as ‗Redirection‘.
6. SERVICES: System administrators monitor the system and help users. When necessary,
UNIX also includes the support utilities for system administrator and control.
7. FLEXIBLE: UNIX operating system is flexible because of number of factors like
(i)Better data stability
(ii) greater security
(iii)greater stability
(iv)compatability
(v)pipe commands
Prof. KARTHIK S -Dept. of Computer Applications CIT,MANDYA
UNIX AND SHELL SCRIPTING
8. OPEN SOURCE SYSTEM: UNIX is an operating source system ,UNIX code will be
available in the internet. Open source means you can get the source code for free of cost.
9. SCALABLE: UNIX system is scalable because it allows more number of users and
the performance does not decrease for adding the new user.
Applications of UNIX Operating System:
1. Server management
2. Software development
3. Networking
4. Scientific research
5. Enterprise systems
6. Embedded systems
7. Cloud computing
8. Multi-user environments
History of UNIX
The development of the UNIX operating system began in 1957 and its roots in Bell Labs.
In 1957, Bell Labs required an operating system for their in- house computer centre.
They created BESYS to sequence their jobs and to control the system resources.
In 1964, the researchers from General Electric, MIT, and Bell Labs came together and
created a new general-purpose ,multi-user ,time-sharing operating system known as
Multiplexed Information and Computing System(Multics).
UNIX AND SHELL SCRIPTING
In 1969, the Multics project was withdrawn because of yhe high cost of development and
due to differences among its members. When this happened, Ken Thompson,Dennis
Ritchie, Douglas Ritchie, and Douglas Mcllroy, along with a few others , began working
on Uniplexed Information and Computing System(UNICS) by using an old PDP-7
computer. The name Unics was shortened to Unix.
In 1971, the first edition of Unix appeared along with the B compiler. It intoduced
several well-known Unix commands. Together it included more than 60 commands.
In 1972, the second edition of Unix was released.
In 1973, the third edition of Unix appeared along with the Unix C compiler (cc). In 1973
only he fourth edition released. The kernel was rewritten in the C compiler.
In 1974, the fifth edition of Unix was released. The source code was made freely
available to universities for educational purposes. This led to the formation of the
Berkeley Software Distribution, which was commonly known as BSD.
In 1975, the sixth edition of unix was released. This edition, also known as V6 UNIX .
In 1977, 1BSD ,the first edition , was released; in 1978 ,2BSD,the second edition ,was
released.
In 1979, the seventh edition of Unix was released. The edition was released along Steve
Bourne‘s shell(sh). And also 3BSD ,the third edition was released.
In 1980, 4.0BSD, the fourth version of the Bsd Unix variant ,was released.
In 1982, AT&T transferred its Unix development to Western Electric, which developed
the System iii version of Unix.
In 1983,Western Electric released System V, whereas System IV was reserved for only
AT&T‘s use.
In 1984, the USG group, which renamed the UNIX system development
laboratory(USDL) group, released System V Release 2 (SVR2).
In 1985, the eigth edition was released on the basis of the 4.1BSD version.
In 1987, the USDL group, which was renamed AT&T Information Systems (ATTIS)
group, released System V Release 3(SVR3).
In 1988, the ninth version of Unix was developed, and it was based on the 4.3 BSD
version .
In 1989, the tenth version of Unix was developed.
Prof. KARTHIK S -Dept. of Computer Applications CIT,MANDYA
UNIX AND SHELL SCRIPTING
Architecture of UNIX Operating System
The UNIX operating system is divided into 4 prominent layers that help define the
interaction between the hardware and the user. As we move from layer 1 to layer 4, we
move away from hardware towards the software. UNIX OS consists of a hardware
layer, kernel layer, shell layer, and applications layer. These layers together create a
multiuser, multitasking operating system. The following diagram shows a pictorial
representation of the layers in the UNIX operating system.
1. Hardware Layer :
It contains the hardware-related information required for the functioning of
the UNIX environment.
2. Kernel Layer :
The core (commonly known as the heart) of the operating system. It is a software
application that acts as the interface between the hardware and the user. The kernel is
responsible for handling the major functionality of the Unix Operating System including
process, memory, file, network, etc.
Functions of the Kernel Layer :
o Ensures that all the system and user tasks are executed concurrently.
o Acts as a device manager helping processes gain access to peripheral
devices connected to the computer with the help of device drivers .
o Manages memory using techniques like paging, swapping, and virtual storage.
UNIX AND SHELL SCRIPTING
3. Shell Layer :
The interface between the user and kernel. It is a program
that interprets/translates commands typed into the terminal into a series of commands
that can be sent to the shell. This script containing commands is called a shell script. The
shell is what keeps a history of commands typed in by the user. To repeat a command
previously typed, you can simply click the scroll-up key and you will get access to the
older commands.
UNIX uses multiple shells including Bourne Shell (sh), C shell (csh), Korn shell (ksh),
etc. The initial shell that the user logs into is defined by the system administrator. The
user can change the default shell by using the 'chsh' command.
4. Application Programs Layer :
The outermost layer that includes programs that are accessed by command on the
command line. It executes external applications like word processors and graphic
programs. Although the earlier Command line was the only way to access them,
now GUI can also be used.
Types of Shell in UNIX
In UNIX, a program used to interpret commands sent by the user to the operating system
is called a shell. In UNIX, users are free to select a shell of their choice. Given below are
some commonly used shells that you should be aware of :
Bourne Shell:
The first shell used for the UNIX operating system, the Bourne Shell is also simply
called the Shell. It is still the most widely used due to its high functionality. This is
represented as sh.
C Shell:
As the name suggests, the C shell in UNIX is used to allow users to write shell
scripts using a syntax similar to the C language. It was developed to remove the
limitations of the Bourne Shell. It is commonly known as csh.
Prof. KARTHIK S -Dept. of Computer Applications CIT,MANDYA
UNIX AND SHELL SCRIPTING
Korn Shell:
It was created by David Korn to address the drawbacks of Bourne and C shell, the Korn
Shell. It merges all features in one package and provides developers with the ability to
create new shell commands. It is also known as ksh.
Experience the Unix environment
Experiencing the UNIX environment means learning how to interact with the UNIX
operating system using its commands, file system, and process management features. It
involves understanding how users communicate with the system through the shell and how
system resources are managed.
To experience the UNIX environment, a user should understand and perform the following:
1. Log in to the system
2. Use shell commands
3. Navigate file system
4. Manage files and permissions
5. Control processes
6. Use redirection and pipes
1. Login to the System
Enter the username and password to access the UNIX system and reach the shell prompt.
Example:
login: student
password: *****
2. Use the Shell
The shell acts as an interface between the user and the kernel.
It reads the command entered by the user, interprets it, and executes it.
Interact with the system using shell commands such as
$ date → Displays current date and time
$ who → Shows logged-in users
$ cal → Displays calendar
$ clear → Clears the screen
Prof. KARTHIK S -Dept. of Computer Applications CIT,MANDYA
UNIX AND SHELL SCRIPTING
3. Navigate the File System
UNIX uses a hierarchical directory structure starting from the root directory /.
Important directories:
/ → Root directory
/home → User directories
/bin → System commands
/etc → Configuration files
Move between directories using commands like pwd, cd, and ls.
Command Function
pwd Shows current directory
ls Lists files
cd Changes directory
4. Work with Files and Directories
Create, copy, move, and delete files using touch, cp, mv, rm, mkdir, etc.
$ touch [Link] → Create file
$ cat [Link] → Display file content
$ cp file1 file2 → Copy file
$ mv file1 file2 → Rename/Move file
$ rm file1 → Delete file
5. Manage File Permissions
View and change permissions using ls -l and chmod.
UNIX provides security through file permissions.
Each file has:
Read (r)
Write (w)
Execute (x)
6. Manage Processes and Use Redirection
Control running programs using ps, kill and use redirection (>, <) and pipes (|) to
combine commands.
UNIX is a multi-tasking operating system. Many processes can run at the same time.
Prof. KARTHIK S -Dept. of Computer Applications CIT,MANDYA
UNIX AND SHELL SCRIPTING
Commands:
$ ps → Shows running processes
$ top → Displays active processes
$ kill → Terminates process
Redirection & pipes
Output Redirection
$ ls > [Link]
Input Redirection
$ wc < [Link]
Pipes
$ ls | wc -l
THE UNIX ENVIRONMENT
UNIX is a multiuser, portable operating system designed to facilitate
programming, text processing, communication and many other tasks that are expected
from an operating system.
Its flexibility is demonstrated in that it is used in three different computing environments:
(i)Stand-alone Environment
(ii) Time-sharing Environment
(iii) Client/Server systems
PERSONAL ENVIRONMENT:
Although originally designed to facilitate programming as a multiuser environment,
many users are installing UNIX on their personal computers. This trend to personal
UNIX systems accerlated in mid-1990‘s with availability of unix , a tree UNIX system.
The Apple system X, released in 2001,incorporated UNIX as its kernel.
TIME-SHARING ENVIRONMENT:
Employees in large companies often work in what is known as Time-Sharing
Environment. In a time-sharing environment, the output devices(suah as printers) and
auxilary storage devices are shared by all of the users. In time sharing environment ,all of
the computing must be done by the cental computer. In other words, it must also control
the shared resources, it must manage the shared data and printing and it must also do
computing.
Prof. KARTHIK S -Dept. of Computer Applications CIT,MANDYA
UNIX AND SHELL SCRIPTING
CLIENT/SERVER ENVIRONMENT:
A Client/Server computing environment spilts the computing function between a central
computers and users computers. The user‘s microcomputers or workstations are called
‗Client‘. The central computer which may be powerful microcomputer, or
minicomputer,or central frame system, is known as ―Server . As workis shared,
response time and monitor display are faster and users are more productive.
UNIX AND SHELL SCRIPTING
Basic commands
Command Purpose / Description Example Output / Notes
Shows file details (permissions, owner,
$ ls -l
ls List files and directories $ ls -a
size, date)
Includes hidden files (starting with .)
Display file contents or $ cat [Link] Prints content of [Link]
cat
concatenate files $ cat file1 file2 Prints contents of both files sequentially
$ cal Shows current month
cal Display calendar $ cal 2026 Shows calendar of year 2026
date Display current date and time $ date Thu Feb 11 12:34:56 IST 2026
List events or display calendar Shows upcoming events stored in system
calendar $ calendar
(if configured) calendar
who Show currently logged-in users $ who student tty1 Feb 11 08:00
tty Show current terminal device $ tty /dev/tty1
Linux hostname 5.15.0-70-generic
uname Display system information $ uname -a
x86_64 GNU/Linux
Prompts: Old password → New
passwd Change user password $ passwd
password → Confirm password
Print message or value of a $ echo Hello Hello
echo
variable $ echo $HOME /home/student
$ printf "Hello
printf Print formatted output %s\n" Student Hello Student
Terminal control (colors, $ tput setaf 1 Sets text color to red
tput
cursor, screen) $ tput cup 5 10 Moves cursor to row 5, column 10
Basic calculator (supports $ bc → 5+3 8
bc
arithmetic & decimals) scale=2 → 10/3 3.33
1. ls
• ls command can be used to obtain a list of all file names in the current directory.
• -l option can be used to obtain a detailed list of attributes of all files in the current directory.
• Example:
$ls-l
Type&PermLink Owner
Group Size Date&Time FileName
-rwxr-xr-- 1 kumar metal 195 may10 13:45 chap01
drwxr-xr-x 2 kumar metal 512 may09 12:55 helpdir
Prof. KARTHIK S -Dept. of Computer Applications CIT,MANDYA
UNIX AND SHELL SCRIPTING
2. date
• This command can be used to display the current date and time.
• Example:
$date
MonSep416:40:02IST2017
• This command can also be used with suitable format specifiersas arguments.
• Following are some format specifiers:
d – day of month (1 - 31) m - Month (01-12) y–lasttwodigitsoftheyear.
H– hour (00-24) M – minute (00-59) S – second (00-59)
D–date intheformatmm/dd/yy
T – time in the format
hh:mm:ss
• Syntax:
$date+%format_specifier
• Example:
$date+"%d-%m-
%y"04-09-17
$date+%m 09
//displaysmonthnumber
3. passwd
• This command can be used to change user password.
• All Unix systems require passwords to help ensure that your files and detaremain secure
from hackers.
• Following are the steps to change your password–
1) To start, type password at the command prompt as shown below.
2) Enter your old password ,the one you're currently using.
3) Type in your new password.
4) You must verify the password by typing it again.
Prof. KARTHIK S -Dept. of Computer Applications CIT,MANDYA
UNIX AND SHELL SCRIPTING
$passwd
Changing password for kumar
(current) Unix password:
***** New Unix password:
*****RetypenewUnixpasswor
d:*****
passwd:allauthenticationtokensupdatedsuccessfully
$
4. echo
• This command can be used to display a message on the terminal.
• Example:
$echo "Welcome to UNIX\n"
Welcome to UNIX
• This command can be used with following escape characters:
"\a" AudibleAlert(Bell)
"\b‟ BackSpace
"\f‟ FormFeed
"\n‟ NewLine
"\r‟ CarriageReturn
"\t‟ HorizontalTab
"\v‟ VerticalTab
"\\‟ Backslash
5. printf
• This command can be used to display a message on the terminal.
• This command can be used with following escape characters:
"\a" AudibleAlert(Bell)
"\b‟ BackSpace
"\f‟ FormFeed
"\n‟ NewLine
"\r‟ CarriageReturn
"\t‟ HorizontalTab
"\v‟ VerticalTab
"\\‟ Backslash
• Example:
$printf "Welcome toUNIX\n"
Welcome to UNIX
• Similar to C language, this command can be used with following format specifiers:
Prof. KARTHIK S -Dept. of Computer Applications CIT,MANDYA
UNIX AND SHELL SCRIPTING
%d Decimalinteger
%f Floatingpointnumber
%s String
%o Octalinteger(base 8)
%x Hexadecimalinteger(base16)
• Syntax:
printf("format-string",variable-list);
where format – string contains one or more format-
specifiers variable-list contains names of
variables
• Example:
$printf"Mycurrentshellis%s\n"$SHEL
L My current shell is /bin/ksh
Prof. KARTHIK S -Dept. of Computer Applications CIT,MANDYA