SlideShare a Scribd company logo
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.
Introduction to Unix
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

PPTX
12th Five year Plan
PPTX
PPTX
Unix Operating System
PPTX
Linux operating system - Overview
PPTX
Unix Operating System
PPTX
System calls
PPTX
What Is DevOps?
PPTX
IMPORTANCE OF LEADERSHIP
12th Five year Plan
Unix Operating System
Linux operating system - Overview
Unix Operating System
System calls
What Is DevOps?
IMPORTANCE OF LEADERSHIP

What's hot (20)

PPTX
Unix operating system
PPTX
Linux commands
PPTX
Unix operating system architecture with file structure
PPTX
Unix ppt
PDF
Python programming : Control statements
PPTX
Demand Paging in OS (Operating System): Example, Advantages, Working
PPTX
Multithreading models.ppt
PPTX
Process synchronization in Operating Systems
PPTX
Operating system memory management
PPT
Os Threads
PPTX
Loaders ( system programming )
PPTX
Operations on Processes and Cooperating processes
PPT
Linux os and its features
PPT
CPU Scheduling Algorithms
PPT
Operating system.ppt (1)
PPTX
Pipelining powerpoint presentation
PPTX
Programming 1: Compilers, Interpreters & Bytecode
PPTX
file system in operating system
PPT
Structure of a C program
PPTX
Computer registers
Unix operating system
Linux commands
Unix operating system architecture with file structure
Unix ppt
Python programming : Control statements
Demand Paging in OS (Operating System): Example, Advantages, Working
Multithreading models.ppt
Process synchronization in Operating Systems
Operating system memory management
Os Threads
Loaders ( system programming )
Operations on Processes and Cooperating processes
Linux os and its features
CPU Scheduling Algorithms
Operating system.ppt (1)
Pipelining powerpoint presentation
Programming 1: Compilers, Interpreters & Bytecode
file system in operating system
Structure of a C program
Computer registers
Ad

Similar to Introduction to Unix (20)

PPT
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
DOCX
UNIT II-Programming in Linux
PPTX
Unix case-study
PPT
Spsl unit1
PPT
LinuxOS-1 (1).ppt
PPTX
Unix / Linux Operating System introduction.
PPTX
Shells commands, file structure, directory structure.pptx
PPTX
Linux Operating System
DOC
84640411 study-of-unix-os
PPTX
Operating system
PPTX
UNIX_module1.pptx
PPTX
Unix and shell programming | Unix File System | Unix File Permission | Blocks
PDF
3CS LSP UNIT 1-1.pdf
PPT
16. Computer Systems Basic Software 2
PDF
UNIX_Module 1.pdf
PDF
1_Introduction_To_Unix_and_Basic_Unix_Commands
PPTX
linux m1 part 1 notes in mca departement.pptx
PPTX
CHAPTER 1 INTRODUCTION TO UNIX.pptx
PPTX
18 LINUX OS.pptx Linux command is basic isma
PPTX
Cha-2- Software Maintenance Part-2.gghgpptx
Introduction to Unix operating system Chapter 1-PPT Mrs.Sowmya Jyothi
UNIT II-Programming in Linux
Unix case-study
Spsl unit1
LinuxOS-1 (1).ppt
Unix / Linux Operating System introduction.
Shells commands, file structure, directory structure.pptx
Linux Operating System
84640411 study-of-unix-os
Operating system
UNIX_module1.pptx
Unix and shell programming | Unix File System | Unix File Permission | Blocks
3CS LSP UNIT 1-1.pdf
16. Computer Systems Basic Software 2
UNIX_Module 1.pdf
1_Introduction_To_Unix_and_Basic_Unix_Commands
linux m1 part 1 notes in mca departement.pptx
CHAPTER 1 INTRODUCTION TO UNIX.pptx
18 LINUX OS.pptx Linux command is basic isma
Cha-2- Software Maintenance Part-2.gghgpptx
Ad

More from Nishant Munjal (20)

PPTX
Database Management System
PPTX
Functions & Recursion
PPTX
Array, string and pointer
PPTX
Programming in C
PPTX
Introduction to computers
PPTX
Unix Administration
PPTX
Shell Programming Concept
PPTX
VI Editor
PPTX
Routing Techniques
PPTX
Asynchronous Transfer Mode
PPTX
Overview of Cloud Computing
PPTX
SQL Queries Information
PPTX
Database Design and Normalization Techniques
PPTX
Concurrency Control
PPTX
Transaction Processing Concept
PPTX
Database Management System
PPTX
Relational Data Model Introduction
PPTX
Virtualization, A Concept Implementation of Cloud
PPTX
Technical education benchmarks
PPSX
Bluemix Introduction
Database Management System
Functions & Recursion
Array, string and pointer
Programming in C
Introduction to computers
Unix Administration
Shell Programming Concept
VI Editor
Routing Techniques
Asynchronous Transfer Mode
Overview of Cloud Computing
SQL Queries Information
Database Design and Normalization Techniques
Concurrency Control
Transaction Processing Concept
Database Management System
Relational Data Model Introduction
Virtualization, A Concept Implementation of Cloud
Technical education benchmarks
Bluemix Introduction

Recently uploaded (20)

PPTX
Geodesy 1.pptx...............................................
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PDF
composite construction of structures.pdf
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
“Next-Gen AI: Trends Reshaping Our World”
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
Practice Questions on recent development part 1.pptx
PPTX
436813905-LNG-Process-Overview-Short.pptx
DOCX
573137875-Attendance-Management-System-original
PPTX
web development for engineering and engineering
PPTX
anatomy of limbus and anterior chamber .pptx
Geodesy 1.pptx...............................................
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
composite construction of structures.pdf
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...
“Next-Gen AI: Trends Reshaping Our World”
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
bas. eng. economics group 4 presentation 1.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Lesson 3_Tessellation.pptx finite Mathematics
Practice Questions on recent development part 1.pptx
436813905-LNG-Process-Overview-Short.pptx
573137875-Attendance-Management-System-original
web development for engineering and engineering
anatomy of limbus and anterior chamber .pptx

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.
  • 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