SlideShare a Scribd company logo
1 of 37
Introduction
UNIX AND SHELL PROGRAMMING
UNIT-I
Overview
 It is designed to let a no. of programmers to access the computers at the same
time and share its resources.
 It is mainly developed by programmers for programmers.
 OS coordinates the use of computer resources.
 Many user can log on at the same time and process their work.
 Initially it was designed for mini computers and later on it moved to larger,
more powerful mainframe computers.
History
 In 1969 Ken Thompson comes up with the idea to make a general purpose
operating system and with the help of Denis Ritche he implemented his idea
and created single user system in Bell Laboratories.
 In 1973, Thompson and Ritche rewrote the UNIX operating system in C,
breaking away from the traditional system software language, Assembly.
 Around 1974, it was licensed to universities for educational purposes and a few
years later UNIX was made commercially available.
Uniqueness of UNIX
The features that made UNIX a hit from the start are:
 Multitasking Capability
 Multi-user Capability
 Unix Programs
 Library of application software.
Multi-User Operating System
Multi-user operating system is expected to perform various functions, which can be
broadly categorized as :
 Command interpretation
 Peripheral Management
 Memory Management- is the extremely important job of allocation memory for
various jobs being performed on the system and even disposing of useless data
in memory after it has been processed and used.
 Process Management
Benefits of UNIX
 Portability
 Machine Independent – the system hides the machine architecture from the user, making it easier
to write the applications that can run or micros, minis and mainframes.
 Multi-user Operations
 Hierarchical file system- UNIX uses a hierarchical structure to store information. This structure has
the maximum flexibility in grouping information in a way that reflects its natural state. It allows for
easy maintenance and efficient implementation.
 Unix Shell
 Pipes and Filters- UNIX has facilities called pipes and filters, which permit the user to create
complex programs from simpler programs.
 Utilities
 Background Processing
 Software Development tools
 Maturity – Unix is a time-tested operating system. It offers a bug free environment and high
level of reliability
How UNIX is organized
Kernel –
 The kernel takes responsibility for deciding at any time which of the many running
programs should be allocated to the processor or processors
 The kernel is responsible for deciding which memory each process can use, and
determining what to do when not enough is available.
 The kernel allocates requests from applications to perform I/O to an appropriate
device (or subsection of a device, in the case of files on a disk or windows on a
display) and provides convenient methods for using the device.
 Kernels also usually provide methods for synchronization and communication
between processes (called inter-process communication or IPC).
Operating system tasks are done differently by different kernels, depending on their design and
implementation.
 Monolithic kernels execute all the operating system code in the same address space to increase the
performance of the system,
 Micro kernels run most of the operating system services in user space as servers, aiming to improve
maintainability and modularity of the operating system.
A range of possibilities exists between these above two extremes.
 If we don’t have kernel then we need to design the application which would be able to
communicate with the hardware not to use abstraction layer. But this will increase the complexity
of the system.
Kernel Working
 The boot loader starts executing the kernel in supervisor mode. The kernel then
initializes itself and starts the first process. After this, the kernel does not
typically execute directly, only in response to external events (e.g., via system
calls used by applications to request services from the kernel, or via interrupts
used by the hardware to notify the kernel of events). Additionally, the kernel
typically provides a loop that is executed whenever no processes are available
to run; this is often called the idle process.
Shell
 It acts as an interpreter between the user and the computer.
 It also provides the functionality of “pipes”.
 Pipes- a number of commands can be linked together by a user permitting the
output of one program to become the input of another program or command.
File System
 The unix file system includes directories containing files and directories, each
directory of which can contain yet more file and files and directories.
 Managing file system is one of the important task of the system administrator.
File Types
There are four types of files in unix-
 Ordinary files :
 An ordinary file may contain text, a program or other data in either ASCII form or in
Binary form.
 Directory files
 Suppose directory x contains a,b,c and that b is a directory, and b contains u and v
files.
 Device files
 Link files
Unix Directory Structure
There are some directories in unix which will install with the unix operating system as a dependency under the root(main) directory are:
 Etc : Contains all system configuration files and the files which maintain information about the user and group.
 Bin : Contains all binary executable
 Usr : default directory provided by UNIX OS to create users home directories and contains manual pages
 Tmp: System or users temporary files which will be removed when the system reboots.
 Dev: Contains all device files i.e. logical names to physical devices.
 Devices : Contains all the device files. i.e. physical names to physical devices.
 Home : default directory allocated for the home directories of normal users when the administrator don’t specify any other directory.
 Var : contains all the system log files and message files.
 Sbin : Contains all the system administrator executable files.
Internal vs External Commands
 Internal Command
 Internal commands are something which is built into the shell. For the shell built in
commands, the execution speed is really high. It is because no process needs to be spawned
for executing it. For example, when using the "cd" command, no process is created. The
current directory simply gets changed on executing it.
 External Command
 External commands are not built into the shell. These are executable present in a separate
file. When an external command has to be executed, a new process has to be spawned and
the command gets executed. For example, when you execute the "cat" command, which
usually is at /usr/bin, the executable /usr/bin/cat gets executed.
 Use keyword “type” to know whether the command is Internal or External.
Major task of system administrator are
 Making files available to users.
 Managing and monitoring the system disk resource.
 Protecting against file corruption, hardware failures, user errors through backup.
 Security of these filesystems, what users need and have access to which files.
 Adding more disks, tape drives, etc when needed.
Introduction with UNIX Basic Commands
Directory Handling
 mkdir : used to create a new directory.
 rmdir : used to remove the directory.
 pwd : to find out the path of the directory.
 cd : it is used to change the directory.
Path Variables
 Absolute paths
 cd /home/nishant
 cd /home/nishant/my
 Relative paths
 cd ../nishant/my
 cd ~nishant/my
File Operations
 cat
 cat > newfile: will create a new file.
 cat newfile: will show all the data of the newfile.
 cp
 cp file1 file2 : will create a new file which is the copy of file1 with the name of file2.
 rm
 rm file1: will delete the file1.
 rm –r mydir: will delete the directory named mydir.
 mv
…
 ls
 ls : will list all the files and directories currently present in the directory.
 ls –a: will list all the files including hidden files.
 ls –l : will list all the files currently into the directory and also all the details of it.
 Ln
 ln x y: will create a shortcut of the file x with the new name y.
 chown
 chown username filename: will change the file owner.
 chmod
 chmod options filename: will change the permissions of the file.
Process Operations
 ps
 ps -aux: will show all the process running into the system currently.
 ps -u username: will show all the process related to that user only.
 Kill
 kill process_id: will kill the specific process.
General Purpose Utilities
 Cal
 Date
 Echo
 printf- Formatted output.
 Bc- echo “2+3” | bc. Evaluates the expression.
 Script- creates a log file for all the commands between script and exit command.
 Passwd
 Who- displays list of users currently logged in.
 Uname- it writes the operating system characteristics.
Understanding UNIX / Linux filesystem
Inodes
 The inode (index node) is a fundamental concept in the Linux and UNIX filesystem. Each
object in the filesystem is represented by an inode. But what are the objects? Let us try to
understand it in simple words. Each and every file under Linux (and UNIX) has following
attributes:
 => File type (executable, block special etc)
=> Permissions (read, write etc)
=> Owner
=> Group
=> File Size
=> File access, change and modification time (remember UNIX or Linux never stores file
creation time, this is favourite question asked in UNIX/Linux system admin job interview)
=> File deletion time
=> Number of links (soft/hard)
=> Extended attribute such as append only or no one can delete file including root user
(immutability)
=> Access Control List (ACLs)
All the above information stored in an inode. In short the inode identifies the file and its
attributes (as above) . Each inode is identified by a unique inode number within the file
system. Inode is also know as index number.
Inode Definition
An inode is a data structure on a traditional Unix-style file system such as UFS or ext3. An
inode stores basic information about a regular file, directory, or other file system object.
$ ls -i /etc/passwd- shows the inode number
Useful Commands
Creating Files
 cat > filename: to create file.
 vi filename
Copying and moving files
 cp filename /destinationfolder/filename
 mv filename newfilename
Creating links
 ln filex filey: will create a shortcut of the filex with the new name filey.
Relative and Absolute Pathnames
 Relative Path Names
The use of the ".." notation allows us to navigate the directory tree structure. The
".." symbol means "parent directory." Names with ".." in them are relative names because
their meaning depends on where they are issued (the present working directory). we can
string together several ".." symbols, separated by the / symbol and other directory names,
to change directories.
 Absolute Path Names
If we string together the unique name of all the intervening subdirectories in the
file system to a particular subdirectory, we have created the absolute pathname for
thatdirectory. The absolute pathname allows us to switch to a directory no matter
what my present working directory is. Absolute pathnames always start with
a "/". we can navigate the file system by using absolute pathnames.
Relative and Absolute Pathnames
Examples
 Relative Path Names Example
$ pwd
/users/john/portfolio
$cd ../../mary
$pwd
/users/mary
 Absolute Path Names Example
$ pwd
/users/john
$ cd /users/mary
$ pwd
/users/mary
$ cd /tmp
$ pwd
File Permissions
 Every user on a Unix system has a unique username, and is a member of at least one
group (the primary group for that user). This group information is held in the
password file (/etc/passwd). A user can also be a member of one or more other
groups. The auxiliary group information is held in the file /etc/group. Only the
administrator can create new groups or add/delete group members (one of the
shortcomings of the system).
Every directory and file on the system has an owner, and also an associated group. It
also has a set of permission flags which specify separate read, write and execute
permissions for the ‘user’ (owner), ‘group’, and ‘other’ (everyone else with an account
on the computer) The ‘ls’ command shows the permissions and group associated with
files when used with the ‘-l’ option. On some systems (e.g. Coos), the ‘-g’ option is also
needed to see the group information.
File Permission Example
 An example of the output produced by ‘ls -l’ is shown below.
drwx—— 2 richard staff 2048 Jan 2 1997 private
drwxrws— 2 richard staff 2048 Jan 2 1997 admin
-rw-rw—- 2 richard staff 12040 Aug 20 1996 admin/userinfo
drwxr-xr-x 3 richard user 2048 May 13 09:27 public
Understanding how to read this output is useful to all unix users, but especially people using group access permissions.
 Field 1: a set of ten permission flags.
 Field 2: link count (don’t worry about this)
 Field 3: owner of the file
 Field 4: associated group for the file
 Field 5: size in bytes
 Field 6-8: date of last modification (format varies, but always 3 fields)
 Field 9: name of file (possibly with path, depending on how ls was called)
Understanding Permissions
Access type File Directory
Read (r) the file can be read by
the corresponding userid or
group to which this set of
symbols applies
If the directory listing can be
obtained
Write (w) The file can be changed or
deleted by the
corresponding user or group
to which this set of symbols
applies
If user or process can change
directory contents somehow:
create new or delete existing files
in the directory or rename files.
Execute (x) The file is considered
executable, and may be
executed by the user or
group to which this set of
symbols applies
If user or process can access the
directory, that is, go to it (make it
to be the current working
directory)
Modes of Changing File Permissions
 Symbolic Mode
$ chmod g+w myfile (symbolic mode)
 Numeric Mode
$ chmod 664 myfie (numeric mode)
Abbrevations:
1. Any combination of u (for “user”), g (for “group”), or o (for “others”), or a (for “all”–
that is, user, group, and others).
2. Any combination of r (for Read), w (for Write), or x (for Execute).
3. Any combination numeric mode: Read(4), Write(2), Execute(1).
Changing Ownership
 CHOWN
 CHGRP
Comparing Files
 diff Command
The UNIX diff command compares the contents of two text files and outputs a list of
differences. If desired, you may instruct it to ignore spacing or case variations. This
command can also verify that two files contain the same data. The syntax is:
diff [options] file1 file2
# diff file1 file2
It lists all differences. A greater-than or less-than symbol appears at the beginning of each
line. "<" means that the text appears in file1, and ">" indicates that it comes from file2.
This UNIX diff command example shows how it works with no options:
Compressing and Decompressing
GZIP Compress
 gzip compresses files. Each single file is compressed into a single file. The
compressed file consists of a GNU zip header and deflated data.
 If given a file as an argument, gzip compresses the file, adds a ".gz" suffix, and
deletes the original file. With no arguments, gzip compresses the standard input
and writes the compressed file to standard output.
$gzip NEW : Compress the file NEW. Creates NEW.gz and deletes NEW
$gzip –c NEW : Compress the file NEW. Creates NEW.gz and do not deletes NEW
GUNZIP Compress
 gunzip uncompresses a file that was compressed with "gzip" or "compress". It
tries to handle both the GNU zip format of gzip and the older Unix compress
format. It does this by recognizing the extension (".gz" or ".Z" or several others)
a file.
 $gunzip NEW.gz : De-Compress the file NEW.gz. Creates NEW and deletes
NEW.gz
 $gzip –c NEW.gz : De-Compress the file NEW.gz. Creates NEW and do not
delete NEW
Thank You

More Related Content

What's hot

Linux architecture
Linux architectureLinux architecture
Linux architecture
mcganesh
 

What's hot (20)

Linux operating system - Overview
Linux operating system - OverviewLinux operating system - Overview
Linux operating system - Overview
 
Know the UNIX Commands
Know the UNIX CommandsKnow the UNIX Commands
Know the UNIX Commands
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Unix Operating System
Unix Operating SystemUnix Operating System
Unix Operating System
 
Linux - Introductions to Linux Operating System
Linux - Introductions to Linux Operating SystemLinux - Introductions to Linux Operating System
Linux - Introductions to Linux Operating System
 
Linux command ppt
Linux command pptLinux command ppt
Linux command ppt
 
Shell programming
Shell programmingShell programming
Shell programming
 
Unix - An Introduction
Unix - An IntroductionUnix - An Introduction
Unix - An Introduction
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Linux basics
Linux basicsLinux basics
Linux basics
 
UNIX Operating System
UNIX Operating SystemUNIX Operating System
UNIX Operating System
 
Unix operating system architecture with file structure
Unix operating system architecture with file structure Unix operating system architecture with file structure
Unix operating system architecture with file structure
 
Linux os and its features
Linux os and its featuresLinux os and its features
Linux os and its features
 
Linux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell ScriptingLinux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell Scripting
 
Basic Unix
Basic UnixBasic Unix
Basic Unix
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Basic commands of linux
Basic commands of linuxBasic commands of linux
Basic commands of linux
 
Unix vs linux
Unix vs linuxUnix vs linux
Unix vs linux
 

Similar to Introduction to Unix

Operating system
Operating systemOperating system
Operating system
HarshithaAllu
 
16. Computer Systems Basic Software 2
16. Computer Systems   Basic Software 216. Computer Systems   Basic Software 2
16. Computer Systems Basic Software 2
New Era University
 
1_Introduction_To_Unix_and_Basic_Unix_Commands
1_Introduction_To_Unix_and_Basic_Unix_Commands1_Introduction_To_Unix_and_Basic_Unix_Commands
1_Introduction_To_Unix_and_Basic_Unix_Commands
Gautam Raja
 

Similar to Introduction to Unix (20)

Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya JyothiIntroduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
 
UNIT II-Programming in Linux
UNIT II-Programming in LinuxUNIT II-Programming in Linux
UNIT II-Programming in Linux
 
Unix case-study
Unix case-studyUnix case-study
Unix case-study
 
Spsl unit1
Spsl   unit1Spsl   unit1
Spsl unit1
 
LinuxOS-1 (1).ppt
LinuxOS-1 (1).pptLinuxOS-1 (1).ppt
LinuxOS-1 (1).ppt
 
Linux Operating System
Linux Operating SystemLinux Operating System
Linux Operating System
 
84640411 study-of-unix-os
84640411 study-of-unix-os84640411 study-of-unix-os
84640411 study-of-unix-os
 
Operating system
Operating systemOperating system
Operating system
 
UNIX_module1.pptx
UNIX_module1.pptxUNIX_module1.pptx
UNIX_module1.pptx
 
Unix and shell programming | Unix File System | Unix File Permission | Blocks
Unix and shell programming | Unix File System | Unix File Permission | BlocksUnix and shell programming | Unix File System | Unix File Permission | Blocks
Unix and shell programming | Unix File System | Unix File Permission | Blocks
 
3CS LSP UNIT 1-1.pdf
3CS LSP UNIT 1-1.pdf3CS LSP UNIT 1-1.pdf
3CS LSP UNIT 1-1.pdf
 
16. Computer Systems Basic Software 2
16. Computer Systems   Basic Software 216. Computer Systems   Basic Software 2
16. Computer Systems Basic Software 2
 
UNIX_Module 1.pdf
UNIX_Module 1.pdfUNIX_Module 1.pdf
UNIX_Module 1.pdf
 
1_Introduction_To_Unix_and_Basic_Unix_Commands
1_Introduction_To_Unix_and_Basic_Unix_Commands1_Introduction_To_Unix_and_Basic_Unix_Commands
1_Introduction_To_Unix_and_Basic_Unix_Commands
 
CHAPTER 1 INTRODUCTION TO UNIX.pptx
CHAPTER 1 INTRODUCTION TO UNIX.pptxCHAPTER 1 INTRODUCTION TO UNIX.pptx
CHAPTER 1 INTRODUCTION TO UNIX.pptx
 
Introduction to unix
Introduction to unixIntroduction to unix
Introduction to unix
 
Introduction to unix (1).pptx
Introduction to unix (1).pptxIntroduction to unix (1).pptx
Introduction to unix (1).pptx
 
Presentation1.pdf
Presentation1.pdfPresentation1.pdf
Presentation1.pdf
 
App A
App AApp A
App A
 
Architecture-of-Linux-operating-system.docx
Architecture-of-Linux-operating-system.docxArchitecture-of-Linux-operating-system.docx
Architecture-of-Linux-operating-system.docx
 

More from Nishant Munjal

More from Nishant Munjal (20)

Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Functions & Recursion
Functions & RecursionFunctions & Recursion
Functions & Recursion
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointer
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Introduction to computers
Introduction to computersIntroduction to computers
Introduction to computers
 
Unix Administration
Unix AdministrationUnix Administration
Unix Administration
 
Shell Programming Concept
Shell Programming ConceptShell Programming Concept
Shell Programming Concept
 
VI Editor
VI EditorVI Editor
VI Editor
 
Routing Techniques
Routing TechniquesRouting Techniques
Routing Techniques
 
Asynchronous Transfer Mode
Asynchronous Transfer ModeAsynchronous Transfer Mode
Asynchronous Transfer Mode
 
Overview of Cloud Computing
Overview of Cloud ComputingOverview of Cloud Computing
Overview of Cloud Computing
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization Techniques
 
Concurrency Control
Concurrency ControlConcurrency Control
Concurrency Control
 
Transaction Processing Concept
Transaction Processing ConceptTransaction Processing Concept
Transaction Processing Concept
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
Virtualization, A Concept Implementation of Cloud
Virtualization, A Concept Implementation of CloudVirtualization, A Concept Implementation of Cloud
Virtualization, A Concept Implementation of Cloud
 
Technical education benchmarks
Technical education benchmarksTechnical education benchmarks
Technical education benchmarks
 
Bluemix Introduction
Bluemix IntroductionBluemix Introduction
Bluemix Introduction
 

Recently uploaded

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Christo Ananth
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 

Recently uploaded (20)

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 

Introduction to Unix

  • 1. Introduction UNIX AND SHELL PROGRAMMING UNIT-I
  • 2. Overview  It is designed to let a no. of programmers to access the computers at the same time and share its resources.  It is mainly developed by programmers for programmers.  OS coordinates the use of computer resources.  Many user can log on at the same time and process their work.  Initially it was designed for mini computers and later on it moved to larger, more powerful mainframe computers.
  • 3. History  In 1969 Ken Thompson comes up with the idea to make a general purpose operating system and with the help of Denis Ritche he implemented his idea and created single user system in Bell Laboratories.  In 1973, Thompson and Ritche rewrote the UNIX operating system in C, breaking away from the traditional system software language, Assembly.  Around 1974, it was licensed to universities for educational purposes and a few years later UNIX was made commercially available.
  • 4. Uniqueness of UNIX The features that made UNIX a hit from the start are:  Multitasking Capability  Multi-user Capability  Unix Programs  Library of application software.
  • 5. Multi-User Operating System Multi-user operating system is expected to perform various functions, which can be broadly categorized as :  Command interpretation  Peripheral Management  Memory Management- is the extremely important job of allocation memory for various jobs being performed on the system and even disposing of useless data in memory after it has been processed and used.  Process Management
  • 6. Benefits of UNIX  Portability  Machine Independent – the system hides the machine architecture from the user, making it easier to write the applications that can run or micros, minis and mainframes.  Multi-user Operations  Hierarchical file system- UNIX uses a hierarchical structure to store information. This structure has the maximum flexibility in grouping information in a way that reflects its natural state. It allows for easy maintenance and efficient implementation.  Unix Shell  Pipes and Filters- UNIX has facilities called pipes and filters, which permit the user to create complex programs from simpler programs.  Utilities  Background Processing  Software Development tools  Maturity – Unix is a time-tested operating system. It offers a bug free environment and high level of reliability
  • 7. How UNIX is organized Kernel –  The kernel takes responsibility for deciding at any time which of the many running programs should be allocated to the processor or processors  The kernel is responsible for deciding which memory each process can use, and determining what to do when not enough is available.  The kernel allocates requests from applications to perform I/O to an appropriate device (or subsection of a device, in the case of files on a disk or windows on a display) and provides convenient methods for using the device.  Kernels also usually provide methods for synchronization and communication between processes (called inter-process communication or IPC).
  • 8. Operating system tasks are done differently by different kernels, depending on their design and implementation.  Monolithic kernels execute all the operating system code in the same address space to increase the performance of the system,  Micro kernels run most of the operating system services in user space as servers, aiming to improve maintainability and modularity of the operating system. A range of possibilities exists between these above two extremes.  If we don’t have kernel then we need to design the application which would be able to communicate with the hardware not to use abstraction layer. But this will increase the complexity of the system.
  • 9. Kernel Working  The boot loader starts executing the kernel in supervisor mode. The kernel then initializes itself and starts the first process. After this, the kernel does not typically execute directly, only in response to external events (e.g., via system calls used by applications to request services from the kernel, or via interrupts used by the hardware to notify the kernel of events). Additionally, the kernel typically provides a loop that is executed whenever no processes are available to run; this is often called the idle process.
  • 10. Shell  It acts as an interpreter between the user and the computer.  It also provides the functionality of “pipes”.  Pipes- a number of commands can be linked together by a user permitting the output of one program to become the input of another program or command.
  • 11.
  • 12. File System  The unix file system includes directories containing files and directories, each directory of which can contain yet more file and files and directories.  Managing file system is one of the important task of the system administrator.
  • 13. File Types There are four types of files in unix-  Ordinary files :  An ordinary file may contain text, a program or other data in either ASCII form or in Binary form.  Directory files  Suppose directory x contains a,b,c and that b is a directory, and b contains u and v files.  Device files  Link files
  • 14. Unix Directory Structure There are some directories in unix which will install with the unix operating system as a dependency under the root(main) directory are:  Etc : Contains all system configuration files and the files which maintain information about the user and group.  Bin : Contains all binary executable  Usr : default directory provided by UNIX OS to create users home directories and contains manual pages  Tmp: System or users temporary files which will be removed when the system reboots.  Dev: Contains all device files i.e. logical names to physical devices.  Devices : Contains all the device files. i.e. physical names to physical devices.  Home : default directory allocated for the home directories of normal users when the administrator don’t specify any other directory.  Var : contains all the system log files and message files.  Sbin : Contains all the system administrator executable files.
  • 15. Internal vs External Commands  Internal Command  Internal commands are something which is built into the shell. For the shell built in commands, the execution speed is really high. It is because no process needs to be spawned for executing it. For example, when using the "cd" command, no process is created. The current directory simply gets changed on executing it.  External Command  External commands are not built into the shell. These are executable present in a separate file. When an external command has to be executed, a new process has to be spawned and the command gets executed. For example, when you execute the "cat" command, which usually is at /usr/bin, the executable /usr/bin/cat gets executed.  Use keyword “type” to know whether the command is Internal or External.
  • 16. Major task of system administrator are  Making files available to users.  Managing and monitoring the system disk resource.  Protecting against file corruption, hardware failures, user errors through backup.  Security of these filesystems, what users need and have access to which files.  Adding more disks, tape drives, etc when needed.
  • 17. Introduction with UNIX Basic Commands
  • 18. Directory Handling  mkdir : used to create a new directory.  rmdir : used to remove the directory.  pwd : to find out the path of the directory.  cd : it is used to change the directory.
  • 19. Path Variables  Absolute paths  cd /home/nishant  cd /home/nishant/my  Relative paths  cd ../nishant/my  cd ~nishant/my
  • 20. File Operations  cat  cat > newfile: will create a new file.  cat newfile: will show all the data of the newfile.  cp  cp file1 file2 : will create a new file which is the copy of file1 with the name of file2.  rm  rm file1: will delete the file1.  rm –r mydir: will delete the directory named mydir.  mv
  • 21. …  ls  ls : will list all the files and directories currently present in the directory.  ls –a: will list all the files including hidden files.  ls –l : will list all the files currently into the directory and also all the details of it.  Ln  ln x y: will create a shortcut of the file x with the new name y.  chown  chown username filename: will change the file owner.  chmod  chmod options filename: will change the permissions of the file.
  • 22. Process Operations  ps  ps -aux: will show all the process running into the system currently.  ps -u username: will show all the process related to that user only.  Kill  kill process_id: will kill the specific process.
  • 23. General Purpose Utilities  Cal  Date  Echo  printf- Formatted output.  Bc- echo “2+3” | bc. Evaluates the expression.  Script- creates a log file for all the commands between script and exit command.  Passwd  Who- displays list of users currently logged in.  Uname- it writes the operating system characteristics.
  • 24. Understanding UNIX / Linux filesystem Inodes  The inode (index node) is a fundamental concept in the Linux and UNIX filesystem. Each object in the filesystem is represented by an inode. But what are the objects? Let us try to understand it in simple words. Each and every file under Linux (and UNIX) has following attributes:  => File type (executable, block special etc) => Permissions (read, write etc) => Owner => Group => File Size => File access, change and modification time (remember UNIX or Linux never stores file creation time, this is favourite question asked in UNIX/Linux system admin job interview) => File deletion time => Number of links (soft/hard) => Extended attribute such as append only or no one can delete file including root user (immutability) => Access Control List (ACLs)
  • 25. All the above information stored in an inode. In short the inode identifies the file and its attributes (as above) . Each inode is identified by a unique inode number within the file system. Inode is also know as index number. Inode Definition An inode is a data structure on a traditional Unix-style file system such as UFS or ext3. An inode stores basic information about a regular file, directory, or other file system object. $ ls -i /etc/passwd- shows the inode number
  • 26. Useful Commands Creating Files  cat > filename: to create file.  vi filename Copying and moving files  cp filename /destinationfolder/filename  mv filename newfilename Creating links  ln filex filey: will create a shortcut of the filex with the new name filey.
  • 27. Relative and Absolute Pathnames  Relative Path Names The use of the ".." notation allows us to navigate the directory tree structure. The ".." symbol means "parent directory." Names with ".." in them are relative names because their meaning depends on where they are issued (the present working directory). we can string together several ".." symbols, separated by the / symbol and other directory names, to change directories.  Absolute Path Names If we string together the unique name of all the intervening subdirectories in the file system to a particular subdirectory, we have created the absolute pathname for thatdirectory. The absolute pathname allows us to switch to a directory no matter what my present working directory is. Absolute pathnames always start with a "/". we can navigate the file system by using absolute pathnames.
  • 28. Relative and Absolute Pathnames Examples  Relative Path Names Example $ pwd /users/john/portfolio $cd ../../mary $pwd /users/mary  Absolute Path Names Example $ pwd /users/john $ cd /users/mary $ pwd /users/mary $ cd /tmp $ pwd
  • 29. File Permissions  Every user on a Unix system has a unique username, and is a member of at least one group (the primary group for that user). This group information is held in the password file (/etc/passwd). A user can also be a member of one or more other groups. The auxiliary group information is held in the file /etc/group. Only the administrator can create new groups or add/delete group members (one of the shortcomings of the system). Every directory and file on the system has an owner, and also an associated group. It also has a set of permission flags which specify separate read, write and execute permissions for the ‘user’ (owner), ‘group’, and ‘other’ (everyone else with an account on the computer) The ‘ls’ command shows the permissions and group associated with files when used with the ‘-l’ option. On some systems (e.g. Coos), the ‘-g’ option is also needed to see the group information.
  • 30. File Permission Example  An example of the output produced by ‘ls -l’ is shown below. drwx—— 2 richard staff 2048 Jan 2 1997 private drwxrws— 2 richard staff 2048 Jan 2 1997 admin -rw-rw—- 2 richard staff 12040 Aug 20 1996 admin/userinfo drwxr-xr-x 3 richard user 2048 May 13 09:27 public Understanding how to read this output is useful to all unix users, but especially people using group access permissions.  Field 1: a set of ten permission flags.  Field 2: link count (don’t worry about this)  Field 3: owner of the file  Field 4: associated group for the file  Field 5: size in bytes  Field 6-8: date of last modification (format varies, but always 3 fields)  Field 9: name of file (possibly with path, depending on how ls was called)
  • 31. Understanding Permissions Access type File Directory Read (r) the file can be read by the corresponding userid or group to which this set of symbols applies If the directory listing can be obtained Write (w) The file can be changed or deleted by the corresponding user or group to which this set of symbols applies If user or process can change directory contents somehow: create new or delete existing files in the directory or rename files. Execute (x) The file is considered executable, and may be executed by the user or group to which this set of symbols applies If user or process can access the directory, that is, go to it (make it to be the current working directory)
  • 32. Modes of Changing File Permissions  Symbolic Mode $ chmod g+w myfile (symbolic mode)  Numeric Mode $ chmod 664 myfie (numeric mode) Abbrevations: 1. Any combination of u (for “user”), g (for “group”), or o (for “others”), or a (for “all”– that is, user, group, and others). 2. Any combination of r (for Read), w (for Write), or x (for Execute). 3. Any combination numeric mode: Read(4), Write(2), Execute(1).
  • 34. Comparing Files  diff Command The UNIX diff command compares the contents of two text files and outputs a list of differences. If desired, you may instruct it to ignore spacing or case variations. This command can also verify that two files contain the same data. The syntax is: diff [options] file1 file2 # diff file1 file2 It lists all differences. A greater-than or less-than symbol appears at the beginning of each line. "<" means that the text appears in file1, and ">" indicates that it comes from file2. This UNIX diff command example shows how it works with no options:
  • 35. Compressing and Decompressing GZIP Compress  gzip compresses files. Each single file is compressed into a single file. The compressed file consists of a GNU zip header and deflated data.  If given a file as an argument, gzip compresses the file, adds a ".gz" suffix, and deletes the original file. With no arguments, gzip compresses the standard input and writes the compressed file to standard output. $gzip NEW : Compress the file NEW. Creates NEW.gz and deletes NEW $gzip –c NEW : Compress the file NEW. Creates NEW.gz and do not deletes NEW
  • 36. GUNZIP Compress  gunzip uncompresses a file that was compressed with "gzip" or "compress". It tries to handle both the GNU zip format of gzip and the older Unix compress format. It does this by recognizing the extension (".gz" or ".Z" or several others) a file.  $gunzip NEW.gz : De-Compress the file NEW.gz. Creates NEW and deletes NEW.gz  $gzip –c NEW.gz : De-Compress the file NEW.gz. Creates NEW and do not delete NEW