SlideShare a Scribd company logo
1 of 74
Module -1
Introduction
Unix is a multi-user, multi-tasking operating system.
You can have many users logged into a system simultaneously, each running many programs.
It's the kernel's job to keep each process and user separate and to regulate access to system hardware,
including cpu, memory, disk and other I/O devices.
There are many different versions of UNIX, although they share common similarities. The most
popular varieties of UNIX are Sun Solaris, GNU/Linux, and MacOS X.
The UNIX operating system is made up of three parts; the kernel, the shell and the programs.
1. The kernel
The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs
and handles the file store and communications in response to system calls.
2. The shell
The shell acts as an interface between the user and the kernel. When a user logs in, the login
program checks the username and password, and then starts another program called the shell. The
shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges
for them to be carried out. The commands are themselves programs: when they terminate, the shell
gives the user another prompt (% on our systems).
HISTORY OF UNIX
First Version was created in Bell Labs in 1969. Some of the Bell Labs programmers who had
worked on this project, Ken Thompson, Dennis Ritchie, Rudd Canaday, and Doug McIlroy designed
and implemented the first version of the Unix File System on a PDP-7 along with a few utilities.
It was given the name UNIX by Brian Kernighan. 00:00:00 Hours, Jan 1, 1970 is time zero for
UNIX. It is also called as epoch.
1973 Unix is re-written mostly in C, a new language developed by Dennis Ritchie. Being written in
this high-level language greatly decreased the effort needed to port it to new machines.
1977 There were about 500 Unix sites world-wide.
1980 BSD 4.1 (Berkeley Software Development)
1983 SunOS, BSD 4.2, System V
1988 AT&T and Sun Microsystems jointly develop System VRelease 4 (SVR4). This later
developed into UnixWare and Solaris 2.
1991 Linux was originated.
WHAT IS LINUX
Linux is a free Unix-type operating system originally created by Linus Torvalds with the assistance of
developers around the world.
It originated in 1991 as a personal project of Linus Torvalds, a Finnish graduate student.
The Kernel version 1.0 was released in 1994 and today the most recent stable version is 2.6.9
Developed under the GNU General Public License , thesource code for Linux is freely available to
everyone.
The UNIX Architecture:
The kernel – shell relationship
1. Division of Labor: Kernel and Shell :
The kernel is the core of the operating system - a collection of routines mostly written in C. it is
loaded into memory when system is booted and communicates directly with the hardware.
The applications (user programs) that need to access the hardware use the services of kernel, these
programs access the kernel through a set of functions called as system calls.
The kernel manages the system’s memory, schedules processes, and decides their priorities.
The shell which is the outer part of the operating system translates the commands into action
(command interpreter).
Even though there’s only one kernel running on the system, there could be several shells in action-
one for each user who is logged in.
When the user enters a command through the keyboard, the sell thoroughly examines the keyboard
input for special characters. If it finds any, it rebuilds a simplified command line, and finally
communicates with the kernel to see that the command is executed.
2. The File and Process:
A file is an array of bytes that stores information. It is also related to another file in the sense that
both belong to a single hierarchical directory structure.
UNIX considers even the directories and device as files.
A process is the second abstraction UNIX provides. It can be treated as a time image of an
executable file. Like files, processes also belong to a hierarchical structure.
3. The system Calls:
These are the set of function calls used by programs to access kernel.
All the UNIX flavors have one thing in common: they use the same system calls.
Ex: A typical command writes a file with the write system call.
The Features of UNIX:
1. Multiuser system:
The system allows multiple users to work on the operating system simultaneously and independently.
 The computer breaks up a unit of time into several segments and each user is allotted a segment, so at
any point in time the machine will be doing the job of a single user.
2. Multitasking system:
UNIX is a multitasking system. In multitasking environment, a user sees one job running in the
foreground; the rest run in the background.
The user can switch jobs between background and foreground, suspend, or even terminate them.
3. Building block approach:
The UNIX commands are developed to perform one simple job.
It’s through the pipes and filters that UNIX implements the small is beautiful philosophy. Today, many
UNIX tools are designed with the requirement that the output of one tool be used as input to another.
By interconnecting a number of tools, user can have a large number of combinations of their usage.
For example: ls (listing the files and directories) and wc –w (word count) were used with | (pipe) to
count the number of files in your directory.
$ ls | wc –w
The commands that can be connected in this way are called filters because they filter data in different
ways
4. The UNIX Toolkit:
To properly exploit the power of UNIX, one should use the host of applications that are shipped with
every UNIX system.
These applications are quite diverse in scope. There are general-purpose tools, text manipulation
utilities, compilers and interpreters, networked applications and system administration tools.
5. Pattern matching:
UNIX features a very sophisticate pattern matching features.
For example: by using the ls command with an unusual argument (chap*) lists all the
filenames starting with chap and ending with anything.
* (known as meta-character) is a special character used by the system to indicate that it
can match a number of filenames.
The matching is not confined to filenames only. Some of the most advanced and useful
tools also use a special expression called regular expression that is framed with meta-
characters.
6. Programming facilities:
The UNIX shell is also a programming language; it was designed for a programmer.
It has all the necessary ingredients, like control structures, loops and variables, that
establish it as a powerful programming language in its own right.
These features are used to design shell scripts.
7. Documentation:
The principle online help facility available is the man command, which remains the
most important reference for commands and their configuration files.
Apart from the online documentation there's a vast ocean of UNIX resources available
on the internet.
There are several newsgroups, blogs and websites that provide information about UNIX.
The UNIX Environment:
UNIX is used in three different computer environments: Personal environment, Time sharing
environment, Client/Server environment.
1. Personal Environment:
 Although originally designed as a multiuser environment, many users are installing UNIX on
their personal computers.
 The trend of personal UNIX systems accelerated in the mid 1990’s with the availability of
LINUX, the Apple system X, released in 2001, incorporated UNIX as its kernel.
2. Time-Sharing Environment:
 In Time-Sharing environment, many users are connected to one or more computers. Their
terminals are non-programmable.
 Output devices (such as printers) and auxiliary storage devices (such as disks) are shared by all
of the users.+
 All the computing must be done by the central computer, it must control the shared resources, it
must manage the shared data and printing, and it must also do the computing.
 All these work tend to keep the computer busy and the responses will be slow.
 A typical college lab in which a minicomputer is shared by many students is shown in the
figure.
Time Sharing Environment
3. Client/Server Environment:
A Client/Server computing environment splits the computing function between a central computer
and users’ computers.
The users are given personal computers or workstations so that some computation responsibility
can be moved off the central computer and assigned to the workstations.
In the Client/Server environment, the users’ workstations are called as the Client. The central
computer system is known as the Server.
Since the work is shared between the client and server, the response time and monitor display are
faster and users are more productive.
A typical Client/Server environment is shown in the figure below:
Clien/Server Environment
UNIX Structure (Components of UNIX):
UNIX consists of four major components: the Kernel, the Shell, a standard set of Utilities and Application
programs. These components are shown in the figure below:
The Kernel:
 Kernel is the heart (core) of the UNIX operating system.
 It contains most basic parts including process control and resource management.
 All the other components call on the kernel to perform these services for them.
The Shell:
 It receives and interprets the commands entered by the user.
 To do any operations in the system, user must give the Shell a command. If the command requires a
utility, the shell requests that the kernel execute the utility. If the command requires an application
program, the shell request that it be run.
 There are two major parts of a shell. The first is the Interpreter; the second part of the shell is a
programming capability that allows you to write a shell script.
 The shells are shown in the figure below:
Some Standard UNIX Shells
Utilities:
 A Utility is a standard UNIX program that provides a support process for users.
 There are literally hundreds of UNIX utilities. Three common utilities are text editors, search
programs, and sort programs.
 For example: vi (text editor), the list (ls) utility displays the files that reside on the disk.
Applications:
 Applications are programs that are not a standard part of UNIX.
 These are written by system administrators, professional programmers or users, they provide an
extended capability to the system.
 Many standard utilities started out as application years ago and proved so useful that they are now
part of the system.
POSIX and the Single UNIX Specification:
•The group of standards, the Portable Operating System Interface for Computer
Environments (POSIX), was developed based on the instructions given by Institution of
Electrical and Electronics Engineers (IEEE).
•POSIX refers to the operating system in general, but was based on UNIX. Two of the most-
cited standards from the POSIX family are known as POSIX.1 and POSIX.2.
•POSIX.1 specifies the system calls.
•POSIX.2 specifies the shell and utilities.
•In 2001, a joint initiative of X/Open and IEEE resulted in the unification of the two
standards, this is the Single UNIX Specification, Version 3 (SUSV3).
•The “Write once, adopt everywhere” approach to this development means that once
software has been developed on any POSIX compliant UNIX system, it can be easily ported
to another POSIX-complaint UNIX machine with minimum modifications.
ACCESSING UNIX
There are three methods for accessing the unix
• User ID
• Passwords
• Interactive session
User ID
•when you work with your own computer at home, you do not need to log in or be too concerned about
who uses the system.
•When you work in a UNIX environment, security and user control becomes major concerns.
•Permission comes in the form of account created by system admin.
•you and your account are identified by a special code known as User id
Passwords
•A password is a word or string of characters used for user authentication to prove identity or access
approval to gain access to a resource (example: an access code is a type of password), which is to be
kept secret from those not allowed access.
•A good password has at least 6 characters.
•It should contain both upper and lower case letters along with at least one digit and special character.
The Login Prompt:
The interactive session contains three steps: login, interaction and logout. The interactive
session is shown in the figure below:
Login:
The general pattern for login is listed as follows:
1.You must make contact with the system.
If you are working on a local network and are always connected to remote server, starting the login
process is as simple as selecting an option in a menu.
On the other hand, if you are making a connection from the remote location, then you will need to
use special connection software, often referred as Telnet software.
2. Wait for system login prompt.
Once you have connected to the server, you must wait for the server to ask you to identify yourself
This is usually just a login prompt, sometimes with the name of the system. A typical login prompt
is :
Interactive Session
3.Type user id.
Enter your user id. Note that UNIX is a case-sensitive system. This means that the uppercase letter
A is different than the lowercase a.
Usually, your user id is all lowercase. If it contains both uppercase and lowercase, you must type
exactly as it was given to you
Login: username
4.Type your password.
After you enter your user id, the system will prompt you for your password.
As you type your password, it will not be displayed on the screen; the system displays an asterisk
for each letter of the password. Some systems don’t even display the asterisks; they just leave the
screen blank.
Password: ******
•If you do everything correctly, you will see the shell prompt. If you make a mistake, the system will give
you a error message
Interaction:
•Once you connect to the server, you can enter commands that allow you to work with computer.
•The result will be displayed on the terminal for all the valid user commands.
Logout:
• It is very important to logout when you are through with the system. There are several reasons for this.
•First, it frees system resources for others who may need to use them.
•Some unauthorized person may walk up and gain access to the system, and your files.
General Features of UNIX commands/ Command Structure:
A UNIX command is an action request given to the UNIX shell for execution.
The simplest commands are a single line entered at the command line prompt that cause a
program or shell script to be executed.
Commands are entered at shell prompt.
The components of the command line are:
•The verb
•Any options required by the command
•The command's arguments (if required)
For example, the general form of a UNIX command is:
$verb [-option(s)] [argument(s)]
• Verb:
•The Verb is the command name. The command indicates what action is to be taken
•Command name and options/arguments have to be separated by spaces or tabs to enable the system to
interpret them as words. Single or multiple spaces can be given to separate the commands and
options/arguments.
Ex: $ cat README
The Shell compresses these multiple spaces to a single space.
•Options:
•The Option modifies how the action is applied. For example, when we display the date, we can use an
option to specify if we want the time in GMT or local time.
•Options are usually one character preceded by a minus sign or plus sign.
Ex: $ wc -c filename
-c is the option to the command wc (-c indicate character count).
•Options can normally be combined with only one – sign, i.e., instead of using
$ wc –c –w filename
You might as well use
$ wc –cw filename
To obtain the same output
•Arguments:
•The Arguments provide additional information to the command. For example, when displaying the
contents of a file, an argument can be used to specify the file name.
•Some commands may accept single argument, some may accept multiple arguments and some
commands may not accept any arguments.
•Ex:
$ wc abc def xyz
Where abc, def and xyz are the filename arguments to the command wc.
Basic Commands
1. echo: Displaying a message
The echo command copies its arguments back to the terminal.
Example1: displaying a message
$ echo Hello World
Hello World
$ echo “Error 105: Invalid Total Sales”
Error 105: Invalid Total Sales
$_
•Example 2: displaying a message in multiple lines; this can be achieved by specifying the
message to printed with double quotes (“ “), when [Enter] is pressed, secondary prompt
will be shown (>).
$ echo “UNIX
> Linux
> Ubuntu “
UNIX
Linux
Ubuntu
$ _
2. printf: An alternate to echo
The printf command is an alternate to echo and performs the similar operation performed by echo
command.
Unlike echo it doesn’t automatically insert a newline unless the n is used explicitly.
•Example 1:
$ printf “ No filename Entered”
No filename Entered
$_
(Note: quotes are not mandatory, but it’s a good discipline to use them)
•Example 2:
$ printf “No filename Entered n”
No filename Entered
$_
3. ls: Listing Directory Contents
ls command lists all filenames in the current directory.
The filenames in the current directory is arranged in ASCII collating sequence (numbers first,
uppercase and then lowercase), with one filename in each line.
Directories often contain many files, and you may simply be interested in only knowing whether
a particular file(s) is available. In that case, just use ls with the filename(s).
If the file isn’t available, then the system will display the appropriate message.
Syntax:
The syntax for the ls command is:
ls [options] [names]
Example :
$ ls calendar
calendar
$ ls perl
Perl: No such file or directory
4. who: Who are the users ?
•UNIX maintains an account of all users who are logged on to the system. The who command displays
an informative listing of these users:
•Example 1:
$ who
Root console Aug 1 07:51 (:0)
kumar pts/10 Aug 1 07:56 (pc123.heavens.com)
sharma pts/6 Aug 1 02:10 (pc125.heavens.com)
sachin pts/14 Aug 1 08:36 (mercury.heavens.com)
The first column shows the usernames (or user-ids) of users currently working in the system.
The second column shows the device names of their respective terminals. The third, fourth and fifth
columns show the date and time of logging in, the last column shows the machine name from where
the user has logged in.
The –H option prints the column headers, when combined with the –u option, provides a more
detailed list.
Example 2:
$ who -uH
NAME LINE TIME IDLE PID COMMENTS
root console Aug 1 07:51 0:48 11040 (:0)
kumar pts/10 Aug 1 07:56 0:33 11200 (pc123.heavens.com)
sachin pts/14 Aug 1 08:36 . 13678 (mercury.heavens.com)
•The first five columns are the same as before, the sixth one represent the IDLE TIME,
which indicate how long it has been since there was any activity on the line.
•If the IDLE time is 0:48, it indicates that the user has no activity since 0 hours and 48
minutes.
•If the IDLE time is . (dot) it indicates that the user has something in the last minute.
•If the IDLE time is old it indicates that the user had no activity over 24 hours.
•The seventh column shows the process id (PID) of the process.
5. Date: Displaying the system date
•You can display the current date with the date command, which shows the date
and time to the nearest second.
•Example 1:
$ date
Wed Mar 6 16:22:40 IST
2005
•The command can be used with –u option to display the Greenwich Mean Time
(GMT):
Example 2:
$ date –u
Wed Apr 3 16:22:40 GMT
2005
•The command can be used with suitable format specifiers as arguments. Each format is
preceded by the + symbol, followed by the % operator, and a single character describing
the format (format code).
Example 3:
$ date +%m
06
•The list of all the format specifiers is shown in the table below.
Format Code Explaination
a Abbreviated weekday name, such as Mon
A Full weekday name, such as Monday
b Abbreviated month name, such as Jan
B Full month name, such as January
d Day of the month with two digits (leading zeros), such as 01,02
D Date in format mm//dd/yy,such as 01/01/99
e Day of themonth with spaces replacing leading zeros, such as 1,2
H Military time two-digit hour, such as 00,01,...,23
I Civilian time two digit hour, such as 00,01,....12
j Julian date (day of the year), such as 001,002,...366
m Numeric two digit month, such as , 01,02,....12
M Two digit minute, such as 01,02,....12
n Newline character
p Display am or pm
r Time in format hour: minute:second with am/pm
R Time in format hour:minute
S Seconds as decimal number [00-61]
t Tab character
T Time in format hour:minute:second
U Week number of the year, such as 00,01...53
W Week of year [00-53] with monday being the first day of week
y Year within century
Y Year as ccyy
Z Time zone name, or no characters if no time zone is determinable
6. cal: The Calendar
•The calendar command, cal, displays the calendar for a specified month or for a year. The
general format of cal command is shown below:
cal [ [month] year ]
•Everything within rectangular brackets is optional, cal can be used without arguments, in
which case it displays the calendar of the current month:
•The syntax also tells us that when cal is used with arguments, the month is optional but
the year is not.
•For example to see the calendar for the month of March 2006, you need two arguments:
7. passwd : Changing your password
•The user password can be changed with the passwd command.
•passwd command expects the user to respond three times. First, it prompts for the old
password. Next, it checks whether you have entered a valid password, and if you have, it
then prompts for the new password, finally the command asks you to reenter the new
password.
•When you enter the password, the string is encrypted by the system.
$ passwd
passwd: Changing password for kumar
Enter login password: ******
New password: *******
Re-enter new password: *******
Passwd (SYSTEM) : passwd successfully changed for kumar
Combining Commands:
•UNIX allows more than one command in the command line.
•Each command has to be separated by a ; (semicolon)
•Example 1: output of wc command will be displayed on the first line followed by the output of date
command.
$ wc note ; date
•Example 2: user may like to group them together within parenthesis and redirect the output to a
disk file.
$ ( wc note ; date ) > newlist
•When a command line contains a semicolon, the shell understands that the command on each side of
it needs to be processed separately.
•Sometimes, you'll find it necessary or desirable to split a long command line into multiple
lines. In that case, the shell issues a secondary prompt, usually >, to indicate to you that
the command line isn‘t complete. This is easily shown with the echo command:
$echo “this is
> a three-line
>text message”
output:
this is
a three-line
text message
Internal and External commands:
UNIX commands are classified into two types
1) Internal Commands - Ex: echo
2) External Commands - Ex: ls, cat
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.
type command:
$ type cd
cd is a shell builtin
$ type cat
cat is /bin/cat
For the internal commands, the type command will clearly say its shell built-
in, however for the external commands, it gives the path of the command
from where it is executed.
How to find out whether a command is internal or external?
THE TYPE COMMAND: knowing the type of a command
and locating it.
•The easiest way of knowing the location of an executable program is to use the type
command.
Example :
$ type ls
ls is /bin/ls
•When the user execute the ls command, the shell locates this file in the /bin directory and
makes arrangement to execute it.
•There are few commands which cannot be located in the file system i.e., the path of the
command is not displayed when it is used with type command.
Example: $ type echo
echo is shell builtin
•Using type command it is possible to determine the command type (internal or external).
•If the output of type command displays the location of the program in the system, then
such command are branded as an External command, ex: ls.
•If the type command output doesn’t specify the location path, instead displays the
message “shell builtin” then such commands are called as Internal command, ex: echo.
THE MAN COMMAND
•The man command knowing more about Unix commands and using Unix online manual
pages
•man is the system's manual viewer; it can be used to display manual pages, scroll up and
down, search for occurrences of specific text, and other useful functions.
•man displays the documentation often called the man documentation of practically every
command on the system.
A man page is divided into a number of compulsory and optional sections. Every command
doesn’t have all sections, but the first three are generally seen in all man pages.
NAME presents a one-line introduction to the command.
SYNOPIS shows the syntax used by the command.
DESCRIPTION provides a detailed description.
•The SYNOPSIS follows certain conventions and rules which every user must understand:
If the command argument is enclosed in rectangular brackets [ ], then it is optional;
otherwise, the argument is required.
The ellipsis (set of three dots) implies that there can be more instances of preceding
word. The expression [ file . . . ] signifies more than one filename as argument.
If you can find the character | in any of these areas, it means that only one of the
options shown on either side of the pipe can be used.
•The OPTIONS section list all the options used by the command.
•The EXIT STATUS section lists possible error conditions and their numeric representation.
•Example of a man page for wc command is shown below:
KNOWING THE USER TERMINAL
For knowing the user terminal have one command called tty (teletype) command.
This command is simple and needs no arguments.
$ tty
/dev/pts/10
$tty
output is /dev/pts/10
The terminal filename is 10 resident in the pts directory. This directory in turns is under
the /dev directory.
You can use tty in a shell script to control the behavior of the script depending on the
terminal it is invoked from.
The root login
•The UNIX system provides a special login name for the exclusive use of the
administrator; it is called root.
•This account comes with every system. Its password is generally set at the time of
installation of the system and has to be used on logging in:
login: root
password: ********* [Enter]
#_
•The prompt of root is #
•Once you log in as root, you are placed in root’s home directory. Depending on the
system, this directory could be / or /root.
•Most administrative commands are resident in /sbin and /usr/sbin.
Becoming the super user: su command
•Any user can acquire superuser status with the su command if he/she knows the root
password.
•For example, the user Juliet (with home directory /home/Juliet) becomes a superuser
in this way:
$ su
Password: ********* [Enter]
#_
• The current working directory doesn’t change, the # prompt indicates that Juliet
now has the power of the superuser.
• To be in root’s home directory on superuser login, use su –l.
• Creating a User’s environment: su when used with a -, recreates the user’s
environment without taking the login-password route
For example :
su – henry
Temporarily creates henry’s environment. This mode is terminated by using
exit.
•The file is a container for information, we can treat it simply as sequence of
character.
•UNIX system has thousands of files. If you write a program, you add one more
file to the system. When you compile it you add some more. Files grow rapidly,
and if they are not organized properly, you will find it difficult to locate them. So
UNIX has a file system (UFS) to manage or organizes its own files in directory.
File is a collection of records. So, files are divided into three categories
a. Ordinary file
b. Directory file
c. Device file
a. Ordinary Files or regular files
This is the most common file type. It contains only data as a stream of characters.
An ordinary files itself divided into 2 types
1) Text file
2) Binary file
1) Text file: contains only printable characters, and you can often view the contents and
make sense out of them. All C and Java files are example of text file. A text file contains
lines of characters where every line is terminated with the newline character, also known
as linefeed (LF) when you press Enter while inserting text, the LF character is appended
to every line.
You won’t see this character normally, but there is command (od) which can make it
visible.
2) Binary file: it contains both printable and unprintable characters that cover the entire
ASCII range(0 to 255).most UNIX commands are example of binary files, and the object
code and executables that you produce by compiling C programs also binary files.
Picture, sound and video files are binary files as well .
b. Directory files
A Directory Contains no data, but keeps some details of the files and subdirectories that it
contains.
The unix file system is organized with a number of directories and subdirectories, and you
can also create them as and when you need.
 A directory file contains an entry for every file and sub directory that it houses. If you
have 20 files in a directory , there will be 20 entries in the directory.
 Each entry has two components:
The filename
A unique Identification number for the file or directory( called the inode number)
 A directory contains the filename but not the contents of file.
 When you create or remove a file the kernel automatically updates its corresponding
directory by adding or removing the enter i.e inode number associated with that file.
c. Device files
 Used to represent a real physical device such as a printer(printing a file & installing
software from CD ROM or backing up files to tape), tape drive or terminal, used for
Input/Ouput (I/O) operations.
 Unix considers any device attached to the system to be a file - including your terminal:
 By default, a command treats your terminal as the standard input file (stdin) from which
to read its input
 Your terminal is also treated as the standard output file (stdout) to which a command's
output is sent.
 stdin and stdout will be discussed in more detail later.
 Two types of I/O: character and block
 Device file names are generally found inside a single directory structure, /dev.
Other file types
Links: a system to make a file or directory visible in multiple parts of the system's file tree.
(Domain) sockets: a special file type, similar to TCP/IP sockets, providing inter−process
networking protected by the file system's access control.
Named pipes: act more or less like sockets and form a way for processes to communicate with
each other, without using network socket semantics.
NAMING FILES OR WHAT’S IN A (FILE) NAME
a. UNIX permits file names to use most characters, but avoid spaces, tabs and characters that
have a special meaning to the shell, such as:
& ; ( ) | ?  ' " ` [ ] { } < > $ - ! /
b. It is recommended that only the following characters be used in filenames.
c. Alphabetic characters and numerals
d. The period(.), the hyphen(-) and underscore(_)
e. Case Sensitivity: uppercase and lowercase are not the same! These are three different files:
NOVEMBER November november
f. Length: can be up to 256 characters
g. Extensions: may be used to identify types of files
libc.a - archive, library file
program.c - C language source file
alpha2.f - Fortran source file
xwd2ps.o - Object/executable code
mygames.Z - Compressed file
PARENT CHILD RELATIONSHIP/ UNIX FILE SYSTEM
All files in UNIX are related to one another. The file system in unix is a collection of all
ordinary, directory and device files and organized in a hierarchical structure as shown in
below fig.
• The implicit feature of every UNIX file system is that there is a top which serves as
reference point for all files. This top is called root & is represented by a /(front
slash).
• Root is actually a directory.
• The rootdirectory has a number of sub directories under it. These sub directories in
turn have more sub directories and others files under them.
• For instance bin and usr are two directories directly under root, while a second bin and
kumar are sub directories under usr.
• Every file apart from root must have a parent. Thus the home directory is the parent of
kumar , while / is the parent of home and grandparent of kumar.
• If you create a file login.sql under the kumar directory ,then kumar will be the parent
of this file.
The first group contains the files that are made available during system installation:
/bin and /usr/bin: these are the directories where all the commonly used UNIX commands are
found.
 /sbin and /usr/sbin: If there’s a command that you can’t execute but the system administrator
can execute, it would be probably in one of these directories.
 /etc: this directory contains the configuration files of the system. You can change a very
important aspect of system functioning by editing a text file in this directory. Your login name and
password are stored in files /etc/passwd and etc/shadow
 /dev: This directory contains all device files. These files don’t occupy space on disk. there could
be more sub directories like pts, dsk and rdsk in this directory
 /lib and /usr/lib: Contains shared library files and sometimes other kernel-related files.
 /usr and /include: contains the standard header files used by C programs. The statement
#include<stdio.h> used in most C programs referes to the file stdio.h in this directory.
 /usr/share/man: this is where the man pages are stored. There are separate subdirectories
here(like man1,man2 etc) that contains the pages for each section. For instance, the man page of ls
can be found in /usr/share/man/man1 User also work with their own files, they write programs, send
and receive mail and also create temporary files. These files are available in the second group
shown below
 /tmp: the directory where users are allowed to create temporary files. These files are wiped away
regularly by the system
 /var: The variable part of the file system. Contains all your print jobs and your outgoing and
incoming mail.
 /home: On many systems users are housed here. Kumar would have his home directory in
/home/kumar
HOME VARIABLE
When log on to the system, UNIX automatically places you in a directory called the home
directory.
It is created by the system when user account is opened.
 If you log in using the login name SJCIT , you will land up in a directory that could have
the pathname
/home/SJCIT
The shell variable HOME known’s yours home directory
$echo $HOME
/home/SJCIT
You will be doing much of your work in your home directory and subdirectories.
Home variable: it is also called environment variables. Environment variables are a set
of
dynamic named values that can affect the way running processes will behave on a computer.
Here $HOME is a environment variable it indicates the home directory of the current
user: the default argument for the cd built-in command.
PATH VARIABLE:
The PATH environment variable is a colon-delimited list of directories that
your shell searches through when you enter a command.
Program files (executables) are kept in many different places on the Unix
system. Your path tells the Unix shell where to look on the system when you
request a particular program.
To find out what your path is, at the Unix shell prompt echo $PATH
 Your path will look something like the following.
/usr2/username/bin:/usr/local/bin:/usr/bin:.
You will see your username in place of username. Using the above example path,
if you enter the ls command, your shell will look for the appropriate executable
file in the following order:
first, it would look through the directory
/usr2/username/bin, then /usr/local/bin, then /usr/bin, and finally the local
directory, indicated by the . (a period).
ABSOLUTE PATHNAMES:
If the first character of a pathname is / the files location must be determined with respect
to root(/) . Such a pathname is called absolute pathname.
cat /home/kumar
When you have more than one / in a pathname for such / you have to descend one level in
the file system. Thus Kumar is one level below home and two levels below root.
When you specify a file y using front slashes to demarcate the various levels, you have a
mechanism of identifying a file uniquely. No two files in a UNIX system can have same
absolute pathnames.
When you specify the date command, the system has to locate the file date from a list of
directories specified in the PATH variable and then execute it.
 However if you know the location of a command in prior, for example date is usually
located in /bin or /usr/bin . Use absolute pathname i,e precede its name with complete path
$/bin/date
For example if you need to execute program less residing in /usr/local/bin you need to
enter
the absolute pathname
$/usr/local/bin/less
RELATIVE PATHNAMES
 Pathnames that don’t begin with / specify locations relative to your current working
directory.
 Uses either the current or parent directory as reference and specifies path relative to it.
 A relative pathname uses one of these cryptic symbols.
. (a single dot)- this represents the current directory.
.. (two dots) this represents the parent directory
1.Assume the current directory is /home/kumar/progs/data/text, using cd .. will move
one level up
$pwd
/home/kumar/progs/data/text
$ cd ..
$pwd
/home/kumar/progs/data
2.To move two levels up
$pwd
/home/kumar/progs
$ cd ../..
$pwd
/home
3. My present location is /etc/samba and now I want to change directory to /etc.
Using relative path: $ cd ..
Using absolute path: $cd /etc
4.My present location is /var/ftp/ and I want to change the location to /var/log
Using relative path: cd ../log
Using absolute path: cd /var/log
5.My present location is /etc/lvm and I want to change my location to /opt/oradba
Using relative path: cd ../../opt/oradba
Using absolute path: cd /opt/oradba
DIRECTORY COMMANDS – PWD, CD, MKDIR, RMDIR
COMMANDS
pwd (PRINT WORKING DIRECTORY) (checking your current directory)
As the name states, command ‘pwd‘ prints the current working directory or simply the
directory user is, at present. It prints the current directory name with the complete path
starting from root (/).
This command is built in shell command and is available on most of the shell – bash,
Bourne shell, ksh,zsh,
etc.
Basic syntax
$pwd [option]
If both ‘-L‘ and ‘-P‘ options are used, option ‘L‘ is taken into priority. If no option is specified
at the prompt, pwd will avoid all system links, i.e., take option ‘-P‘ into account.
cd: CHANGING THE CURRENT DIRECTORY
The cd command, which stands for "change directory", changes the shell's current
working directory.
The cd command is one of the commands you will use the most at the command line
in UNIX.
It allows you to change your working directory. You use it to move around within the
hierarchy of your file system.
Example- When used with an argument it changes the current directory to the directory
specified as argument for example assume acsce is a directory under user directory
vinutha. To change from vinutha directory to acsce directory , issue the command as
follows
$pwd
/home/ acsce
$cd vinutha
$pwd
/home/ acsce / vinutha
EXAMPLE-2:
When cd used without arguments: cd when used without arguments reverts to home
directory
$pwd
/home/kumar/acsce
$cd
cd without argument will change directory from gmit to its home directory Kumar
$pwd
/home/kumar
EXAMPLE-3:
If your present working directory is /home/Kumar and you need to switch to /bin
directory directly, use absolute pathname i.e /bin wd cd command
$pwd
/home/kumar
$cd /bin
$pwd
/bin
mkdir: "making directory".
mkdir is used to create directories on a file system.
 If the specified DIRECTORY does not already exist, mkdir creates it.
 More than one DIRECTORY may be specified when calling mkdir.
mkdir syntax
mkdir [OPTION ...] DIRECTORY ...
Ex 6.3.1: To create a directory named acsce, issue the following command.
$mkdir acsce
acsce directory is created under present working directory.
Assume that pwd is /home/kumar , then acsce directory is created under kumar directory.
Ex 6.3.2: To create three directories at a time, named patch, dbs, doc, pass directory names
as arguments.
$mkdir patch dbs doc
Ex 6.3.3:To create a directory tree:
To create a directory named acsce and create two subdirectories named cse and ise under
acsce, issue the command.
acsce is a parent directory.
$mkdir parent directory sub-directories
$mkdir acsce acsce/cse acsce/ise
Ex 6.3.4: Error while creating a directory tree
$mkdir acsce/cse gmit/ise
mkdir: Failed to make a directory “acsce/cse”; no such file or directory
mkdir: Failed to make a directory “acsce/ise”; no such file or directory
Error is due to the fact that the parent directory named gmit is not created before creating
sub directories cse and ise.
Ex 6.3.5: $mkdir test
mkdir: Failed to make directory “test”; Permission denied.
This can happen due to:
a. The directory named test may already exist
b. There may be an ordinary file by the same name in the current directory.
c. The permissions set for the current directory do not permit the creation of files and
directories by the
user.
rmdir: REMOVING DIRECTORIES
The rmdir utility removes the directory entry specified by each directory argument,
provided the directory
is empty.
Ex 6.4.1: $rmdir progs
removes the directory named progs Arguments are processed in the order given. To
remove both a parent directory and a subdirectory of that parent, the subdirectory must
be specified first, so the parent directory is empty when rmdir tries to remove it.
The reverse logic of mkdir is applied.
$rmdir subdirectories parent directory
$rmdir acsce/cse acsce/ise acsce
You cant delete a directory with rmdir unless it is empty.In this example gmit directory
cannot be removed until the sub directories cse and ise are removed.
You cant remove a sub directory unless you are place in a directory which is
hierarchically above the one you have chosen to remove.
UNIX_module1.pptx
UNIX_module1.pptx
UNIX_module1.pptx
UNIX_module1.pptx
UNIX_module1.pptx
UNIX_module1.pptx
UNIX_module1.pptx
UNIX_module1.pptx
UNIX_module1.pptx
UNIX_module1.pptx
UNIX_module1.pptx

More Related Content

Similar to UNIX_module1.pptx

Introduction to unix (1).pptx
Introduction to unix (1).pptxIntroduction to unix (1).pptx
Introduction to unix (1).pptxvirat834293
 
UNIT II-Programming in Linux
UNIT II-Programming in LinuxUNIT II-Programming in Linux
UNIT II-Programming in LinuxDr.YNM
 
Unix seminar
Unix seminarUnix seminar
Unix seminarajeet6742
 
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_CommandsGautam Raja
 
Architecture-of-Linux-operating-system.docx
Architecture-of-Linux-operating-system.docxArchitecture-of-Linux-operating-system.docx
Architecture-of-Linux-operating-system.docxVivekGupta920049
 
niyonika.docx
niyonika.docxniyonika.docx
niyonika.docxKunalSri1
 
purnima.docx
purnima.docxpurnima.docx
purnima.docxKunalSri1
 
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 amol_chavan
 
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 | BlocksLOKESH KUMAR
 
Unix shell programming intro-part-1
Unix shell programming intro-part-1Unix shell programming intro-part-1
Unix shell programming intro-part-1Prachi Sasankar
 
Linux Operating System. UOG MARGHAZAR Campus
 Linux Operating System. UOG MARGHAZAR Campus Linux Operating System. UOG MARGHAZAR Campus
Linux Operating System. UOG MARGHAZAR CampusSYEDASADALI38
 
Linux and Java - Understanding and Troubleshooting
Linux and Java - Understanding and TroubleshootingLinux and Java - Understanding and Troubleshooting
Linux and Java - Understanding and TroubleshootingJérôme Kehrli
 
Operating Systems 1
Operating Systems 1Operating Systems 1
Operating Systems 1hutchison
 

Similar to UNIX_module1.pptx (20)

Introduction to unix (1).pptx
Introduction to unix (1).pptxIntroduction to unix (1).pptx
Introduction to unix (1).pptx
 
Spsl unit1
Spsl   unit1Spsl   unit1
Spsl unit1
 
UNIT II-Programming in Linux
UNIT II-Programming in LinuxUNIT II-Programming in Linux
UNIT II-Programming in Linux
 
Module1
Module1Module1
Module1
 
Unix seminar
Unix seminarUnix seminar
Unix seminar
 
Introduction to unix
Introduction to unixIntroduction to unix
Introduction to unix
 
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
 
Architecture-of-Linux-operating-system.docx
Architecture-of-Linux-operating-system.docxArchitecture-of-Linux-operating-system.docx
Architecture-of-Linux-operating-system.docx
 
UNIX_Module 1.pdf
UNIX_Module 1.pdfUNIX_Module 1.pdf
UNIX_Module 1.pdf
 
niyonika.docx
niyonika.docxniyonika.docx
niyonika.docx
 
khushi.docx
khushi.docxkhushi.docx
khushi.docx
 
purnima.docx
purnima.docxpurnima.docx
purnima.docx
 
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
 
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
 
Unix shell programming intro-part-1
Unix shell programming intro-part-1Unix shell programming intro-part-1
Unix shell programming intro-part-1
 
Intro tounix
Intro tounixIntro tounix
Intro tounix
 
Linux Operating System. UOG MARGHAZAR Campus
 Linux Operating System. UOG MARGHAZAR Campus Linux Operating System. UOG MARGHAZAR Campus
Linux Operating System. UOG MARGHAZAR Campus
 
Linux notes
Linux notesLinux notes
Linux notes
 
Linux and Java - Understanding and Troubleshooting
Linux and Java - Understanding and TroubleshootingLinux and Java - Understanding and Troubleshooting
Linux and Java - Understanding and Troubleshooting
 
Operating Systems 1
Operating Systems 1Operating Systems 1
Operating Systems 1
 

Recently uploaded

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 

Recently uploaded (20)

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 

UNIX_module1.pptx

  • 2.
  • 3.
  • 4. Introduction Unix is a multi-user, multi-tasking operating system. You can have many users logged into a system simultaneously, each running many programs. It's the kernel's job to keep each process and user separate and to regulate access to system hardware, including cpu, memory, disk and other I/O devices. There are many different versions of UNIX, although they share common similarities. The most popular varieties of UNIX are Sun Solaris, GNU/Linux, and MacOS X. The UNIX operating system is made up of three parts; the kernel, the shell and the programs. 1. The kernel The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the file store and communications in response to system calls. 2. The shell The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands are themselves programs: when they terminate, the shell gives the user another prompt (% on our systems).
  • 5. HISTORY OF UNIX First Version was created in Bell Labs in 1969. Some of the Bell Labs programmers who had worked on this project, Ken Thompson, Dennis Ritchie, Rudd Canaday, and Doug McIlroy designed and implemented the first version of the Unix File System on a PDP-7 along with a few utilities. It was given the name UNIX by Brian Kernighan. 00:00:00 Hours, Jan 1, 1970 is time zero for UNIX. It is also called as epoch. 1973 Unix is re-written mostly in C, a new language developed by Dennis Ritchie. Being written in this high-level language greatly decreased the effort needed to port it to new machines. 1977 There were about 500 Unix sites world-wide. 1980 BSD 4.1 (Berkeley Software Development) 1983 SunOS, BSD 4.2, System V 1988 AT&T and Sun Microsystems jointly develop System VRelease 4 (SVR4). This later developed into UnixWare and Solaris 2. 1991 Linux was originated.
  • 6. WHAT IS LINUX Linux is a free Unix-type operating system originally created by Linus Torvalds with the assistance of developers around the world. It originated in 1991 as a personal project of Linus Torvalds, a Finnish graduate student. The Kernel version 1.0 was released in 1994 and today the most recent stable version is 2.6.9 Developed under the GNU General Public License , thesource code for Linux is freely available to everyone.
  • 7. The UNIX Architecture: The kernel – shell relationship
  • 8. 1. Division of Labor: Kernel and Shell : The kernel is the core of the operating system - a collection of routines mostly written in C. it is loaded into memory when system is booted and communicates directly with the hardware. The applications (user programs) that need to access the hardware use the services of kernel, these programs access the kernel through a set of functions called as system calls. The kernel manages the system’s memory, schedules processes, and decides their priorities. The shell which is the outer part of the operating system translates the commands into action (command interpreter). Even though there’s only one kernel running on the system, there could be several shells in action- one for each user who is logged in. When the user enters a command through the keyboard, the sell thoroughly examines the keyboard input for special characters. If it finds any, it rebuilds a simplified command line, and finally communicates with the kernel to see that the command is executed.
  • 9. 2. The File and Process: A file is an array of bytes that stores information. It is also related to another file in the sense that both belong to a single hierarchical directory structure. UNIX considers even the directories and device as files. A process is the second abstraction UNIX provides. It can be treated as a time image of an executable file. Like files, processes also belong to a hierarchical structure. 3. The system Calls: These are the set of function calls used by programs to access kernel. All the UNIX flavors have one thing in common: they use the same system calls. Ex: A typical command writes a file with the write system call.
  • 10. The Features of UNIX: 1. Multiuser system: The system allows multiple users to work on the operating system simultaneously and independently.  The computer breaks up a unit of time into several segments and each user is allotted a segment, so at any point in time the machine will be doing the job of a single user. 2. Multitasking system: UNIX is a multitasking system. In multitasking environment, a user sees one job running in the foreground; the rest run in the background. The user can switch jobs between background and foreground, suspend, or even terminate them. 3. Building block approach: The UNIX commands are developed to perform one simple job. It’s through the pipes and filters that UNIX implements the small is beautiful philosophy. Today, many UNIX tools are designed with the requirement that the output of one tool be used as input to another. By interconnecting a number of tools, user can have a large number of combinations of their usage. For example: ls (listing the files and directories) and wc –w (word count) were used with | (pipe) to count the number of files in your directory. $ ls | wc –w The commands that can be connected in this way are called filters because they filter data in different ways 4. The UNIX Toolkit: To properly exploit the power of UNIX, one should use the host of applications that are shipped with every UNIX system. These applications are quite diverse in scope. There are general-purpose tools, text manipulation utilities, compilers and interpreters, networked applications and system administration tools.
  • 11. 5. Pattern matching: UNIX features a very sophisticate pattern matching features. For example: by using the ls command with an unusual argument (chap*) lists all the filenames starting with chap and ending with anything. * (known as meta-character) is a special character used by the system to indicate that it can match a number of filenames. The matching is not confined to filenames only. Some of the most advanced and useful tools also use a special expression called regular expression that is framed with meta- characters. 6. Programming facilities: The UNIX shell is also a programming language; it was designed for a programmer. It has all the necessary ingredients, like control structures, loops and variables, that establish it as a powerful programming language in its own right. These features are used to design shell scripts. 7. Documentation: The principle online help facility available is the man command, which remains the most important reference for commands and their configuration files. Apart from the online documentation there's a vast ocean of UNIX resources available on the internet. There are several newsgroups, blogs and websites that provide information about UNIX.
  • 12. The UNIX Environment: UNIX is used in three different computer environments: Personal environment, Time sharing environment, Client/Server environment. 1. Personal Environment:  Although originally designed as a multiuser environment, many users are installing UNIX on their personal computers.  The trend of personal UNIX systems accelerated in the mid 1990’s with the availability of LINUX, the Apple system X, released in 2001, incorporated UNIX as its kernel. 2. Time-Sharing Environment:  In Time-Sharing environment, many users are connected to one or more computers. Their terminals are non-programmable.  Output devices (such as printers) and auxiliary storage devices (such as disks) are shared by all of the users.+  All the computing must be done by the central computer, it must control the shared resources, it must manage the shared data and printing, and it must also do the computing.  All these work tend to keep the computer busy and the responses will be slow.  A typical college lab in which a minicomputer is shared by many students is shown in the figure.
  • 13. Time Sharing Environment 3. Client/Server Environment: A Client/Server computing environment splits the computing function between a central computer and users’ computers. The users are given personal computers or workstations so that some computation responsibility can be moved off the central computer and assigned to the workstations. In the Client/Server environment, the users’ workstations are called as the Client. The central computer system is known as the Server. Since the work is shared between the client and server, the response time and monitor display are faster and users are more productive. A typical Client/Server environment is shown in the figure below: Clien/Server Environment
  • 14. UNIX Structure (Components of UNIX): UNIX consists of four major components: the Kernel, the Shell, a standard set of Utilities and Application programs. These components are shown in the figure below: The Kernel:  Kernel is the heart (core) of the UNIX operating system.  It contains most basic parts including process control and resource management.  All the other components call on the kernel to perform these services for them. The Shell:  It receives and interprets the commands entered by the user.  To do any operations in the system, user must give the Shell a command. If the command requires a utility, the shell requests that the kernel execute the utility. If the command requires an application program, the shell request that it be run.  There are two major parts of a shell. The first is the Interpreter; the second part of the shell is a programming capability that allows you to write a shell script.  The shells are shown in the figure below:
  • 15. Some Standard UNIX Shells Utilities:  A Utility is a standard UNIX program that provides a support process for users.  There are literally hundreds of UNIX utilities. Three common utilities are text editors, search programs, and sort programs.  For example: vi (text editor), the list (ls) utility displays the files that reside on the disk. Applications:  Applications are programs that are not a standard part of UNIX.  These are written by system administrators, professional programmers or users, they provide an extended capability to the system.  Many standard utilities started out as application years ago and proved so useful that they are now part of the system.
  • 16. POSIX and the Single UNIX Specification: •The group of standards, the Portable Operating System Interface for Computer Environments (POSIX), was developed based on the instructions given by Institution of Electrical and Electronics Engineers (IEEE). •POSIX refers to the operating system in general, but was based on UNIX. Two of the most- cited standards from the POSIX family are known as POSIX.1 and POSIX.2. •POSIX.1 specifies the system calls. •POSIX.2 specifies the shell and utilities. •In 2001, a joint initiative of X/Open and IEEE resulted in the unification of the two standards, this is the Single UNIX Specification, Version 3 (SUSV3). •The “Write once, adopt everywhere” approach to this development means that once software has been developed on any POSIX compliant UNIX system, it can be easily ported to another POSIX-complaint UNIX machine with minimum modifications.
  • 17. ACCESSING UNIX There are three methods for accessing the unix • User ID • Passwords • Interactive session User ID •when you work with your own computer at home, you do not need to log in or be too concerned about who uses the system. •When you work in a UNIX environment, security and user control becomes major concerns. •Permission comes in the form of account created by system admin. •you and your account are identified by a special code known as User id Passwords •A password is a word or string of characters used for user authentication to prove identity or access approval to gain access to a resource (example: an access code is a type of password), which is to be kept secret from those not allowed access. •A good password has at least 6 characters. •It should contain both upper and lower case letters along with at least one digit and special character.
  • 18. The Login Prompt: The interactive session contains three steps: login, interaction and logout. The interactive session is shown in the figure below: Login: The general pattern for login is listed as follows: 1.You must make contact with the system. If you are working on a local network and are always connected to remote server, starting the login process is as simple as selecting an option in a menu. On the other hand, if you are making a connection from the remote location, then you will need to use special connection software, often referred as Telnet software. 2. Wait for system login prompt. Once you have connected to the server, you must wait for the server to ask you to identify yourself This is usually just a login prompt, sometimes with the name of the system. A typical login prompt is : Interactive Session
  • 19. 3.Type user id. Enter your user id. Note that UNIX is a case-sensitive system. This means that the uppercase letter A is different than the lowercase a. Usually, your user id is all lowercase. If it contains both uppercase and lowercase, you must type exactly as it was given to you Login: username 4.Type your password. After you enter your user id, the system will prompt you for your password. As you type your password, it will not be displayed on the screen; the system displays an asterisk for each letter of the password. Some systems don’t even display the asterisks; they just leave the screen blank. Password: ****** •If you do everything correctly, you will see the shell prompt. If you make a mistake, the system will give you a error message Interaction: •Once you connect to the server, you can enter commands that allow you to work with computer. •The result will be displayed on the terminal for all the valid user commands. Logout: • It is very important to logout when you are through with the system. There are several reasons for this. •First, it frees system resources for others who may need to use them. •Some unauthorized person may walk up and gain access to the system, and your files.
  • 20. General Features of UNIX commands/ Command Structure: A UNIX command is an action request given to the UNIX shell for execution. The simplest commands are a single line entered at the command line prompt that cause a program or shell script to be executed.
  • 21. Commands are entered at shell prompt. The components of the command line are: •The verb •Any options required by the command •The command's arguments (if required) For example, the general form of a UNIX command is: $verb [-option(s)] [argument(s)]
  • 22. • Verb: •The Verb is the command name. The command indicates what action is to be taken •Command name and options/arguments have to be separated by spaces or tabs to enable the system to interpret them as words. Single or multiple spaces can be given to separate the commands and options/arguments. Ex: $ cat README The Shell compresses these multiple spaces to a single space. •Options: •The Option modifies how the action is applied. For example, when we display the date, we can use an option to specify if we want the time in GMT or local time. •Options are usually one character preceded by a minus sign or plus sign. Ex: $ wc -c filename -c is the option to the command wc (-c indicate character count). •Options can normally be combined with only one – sign, i.e., instead of using $ wc –c –w filename You might as well use $ wc –cw filename To obtain the same output •Arguments: •The Arguments provide additional information to the command. For example, when displaying the contents of a file, an argument can be used to specify the file name. •Some commands may accept single argument, some may accept multiple arguments and some commands may not accept any arguments. •Ex: $ wc abc def xyz Where abc, def and xyz are the filename arguments to the command wc.
  • 23. Basic Commands 1. echo: Displaying a message The echo command copies its arguments back to the terminal. Example1: displaying a message $ echo Hello World Hello World $ echo “Error 105: Invalid Total Sales” Error 105: Invalid Total Sales $_ •Example 2: displaying a message in multiple lines; this can be achieved by specifying the message to printed with double quotes (“ “), when [Enter] is pressed, secondary prompt will be shown (>). $ echo “UNIX > Linux > Ubuntu “ UNIX Linux Ubuntu $ _
  • 24. 2. printf: An alternate to echo The printf command is an alternate to echo and performs the similar operation performed by echo command. Unlike echo it doesn’t automatically insert a newline unless the n is used explicitly. •Example 1: $ printf “ No filename Entered” No filename Entered $_ (Note: quotes are not mandatory, but it’s a good discipline to use them) •Example 2: $ printf “No filename Entered n” No filename Entered $_
  • 25. 3. ls: Listing Directory Contents ls command lists all filenames in the current directory. The filenames in the current directory is arranged in ASCII collating sequence (numbers first, uppercase and then lowercase), with one filename in each line. Directories often contain many files, and you may simply be interested in only knowing whether a particular file(s) is available. In that case, just use ls with the filename(s). If the file isn’t available, then the system will display the appropriate message. Syntax: The syntax for the ls command is: ls [options] [names] Example : $ ls calendar calendar $ ls perl Perl: No such file or directory
  • 26.
  • 27.
  • 28.
  • 29. 4. who: Who are the users ? •UNIX maintains an account of all users who are logged on to the system. The who command displays an informative listing of these users: •Example 1: $ who Root console Aug 1 07:51 (:0) kumar pts/10 Aug 1 07:56 (pc123.heavens.com) sharma pts/6 Aug 1 02:10 (pc125.heavens.com) sachin pts/14 Aug 1 08:36 (mercury.heavens.com) The first column shows the usernames (or user-ids) of users currently working in the system. The second column shows the device names of their respective terminals. The third, fourth and fifth columns show the date and time of logging in, the last column shows the machine name from where the user has logged in. The –H option prints the column headers, when combined with the –u option, provides a more detailed list.
  • 30. Example 2: $ who -uH NAME LINE TIME IDLE PID COMMENTS root console Aug 1 07:51 0:48 11040 (:0) kumar pts/10 Aug 1 07:56 0:33 11200 (pc123.heavens.com) sachin pts/14 Aug 1 08:36 . 13678 (mercury.heavens.com) •The first five columns are the same as before, the sixth one represent the IDLE TIME, which indicate how long it has been since there was any activity on the line. •If the IDLE time is 0:48, it indicates that the user has no activity since 0 hours and 48 minutes. •If the IDLE time is . (dot) it indicates that the user has something in the last minute. •If the IDLE time is old it indicates that the user had no activity over 24 hours. •The seventh column shows the process id (PID) of the process.
  • 31. 5. Date: Displaying the system date •You can display the current date with the date command, which shows the date and time to the nearest second. •Example 1: $ date Wed Mar 6 16:22:40 IST 2005 •The command can be used with –u option to display the Greenwich Mean Time (GMT): Example 2: $ date –u Wed Apr 3 16:22:40 GMT 2005 •The command can be used with suitable format specifiers as arguments. Each format is preceded by the + symbol, followed by the % operator, and a single character describing the format (format code). Example 3: $ date +%m 06
  • 32. •The list of all the format specifiers is shown in the table below. Format Code Explaination a Abbreviated weekday name, such as Mon A Full weekday name, such as Monday b Abbreviated month name, such as Jan B Full month name, such as January d Day of the month with two digits (leading zeros), such as 01,02 D Date in format mm//dd/yy,such as 01/01/99 e Day of themonth with spaces replacing leading zeros, such as 1,2 H Military time two-digit hour, such as 00,01,...,23 I Civilian time two digit hour, such as 00,01,....12 j Julian date (day of the year), such as 001,002,...366 m Numeric two digit month, such as , 01,02,....12 M Two digit minute, such as 01,02,....12 n Newline character p Display am or pm r Time in format hour: minute:second with am/pm R Time in format hour:minute S Seconds as decimal number [00-61] t Tab character T Time in format hour:minute:second U Week number of the year, such as 00,01...53 W Week of year [00-53] with monday being the first day of week y Year within century Y Year as ccyy Z Time zone name, or no characters if no time zone is determinable
  • 33. 6. cal: The Calendar •The calendar command, cal, displays the calendar for a specified month or for a year. The general format of cal command is shown below: cal [ [month] year ] •Everything within rectangular brackets is optional, cal can be used without arguments, in which case it displays the calendar of the current month: •The syntax also tells us that when cal is used with arguments, the month is optional but the year is not. •For example to see the calendar for the month of March 2006, you need two arguments:
  • 34. 7. passwd : Changing your password •The user password can be changed with the passwd command. •passwd command expects the user to respond three times. First, it prompts for the old password. Next, it checks whether you have entered a valid password, and if you have, it then prompts for the new password, finally the command asks you to reenter the new password. •When you enter the password, the string is encrypted by the system. $ passwd passwd: Changing password for kumar Enter login password: ****** New password: ******* Re-enter new password: ******* Passwd (SYSTEM) : passwd successfully changed for kumar
  • 35. Combining Commands: •UNIX allows more than one command in the command line. •Each command has to be separated by a ; (semicolon) •Example 1: output of wc command will be displayed on the first line followed by the output of date command. $ wc note ; date •Example 2: user may like to group them together within parenthesis and redirect the output to a disk file. $ ( wc note ; date ) > newlist •When a command line contains a semicolon, the shell understands that the command on each side of it needs to be processed separately. •Sometimes, you'll find it necessary or desirable to split a long command line into multiple lines. In that case, the shell issues a secondary prompt, usually >, to indicate to you that the command line isn‘t complete. This is easily shown with the echo command: $echo “this is > a three-line >text message” output: this is a three-line text message
  • 36. Internal and External commands: UNIX commands are classified into two types 1) Internal Commands - Ex: echo 2) External Commands - Ex: ls, cat 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.
  • 37. type command: $ type cd cd is a shell builtin $ type cat cat is /bin/cat For the internal commands, the type command will clearly say its shell built- in, however for the external commands, it gives the path of the command from where it is executed. How to find out whether a command is internal or external?
  • 38. THE TYPE COMMAND: knowing the type of a command and locating it. •The easiest way of knowing the location of an executable program is to use the type command. Example : $ type ls ls is /bin/ls •When the user execute the ls command, the shell locates this file in the /bin directory and makes arrangement to execute it. •There are few commands which cannot be located in the file system i.e., the path of the command is not displayed when it is used with type command. Example: $ type echo echo is shell builtin •Using type command it is possible to determine the command type (internal or external). •If the output of type command displays the location of the program in the system, then such command are branded as an External command, ex: ls. •If the type command output doesn’t specify the location path, instead displays the message “shell builtin” then such commands are called as Internal command, ex: echo.
  • 39. THE MAN COMMAND •The man command knowing more about Unix commands and using Unix online manual pages •man is the system's manual viewer; it can be used to display manual pages, scroll up and down, search for occurrences of specific text, and other useful functions. •man displays the documentation often called the man documentation of practically every command on the system. A man page is divided into a number of compulsory and optional sections. Every command doesn’t have all sections, but the first three are generally seen in all man pages. NAME presents a one-line introduction to the command. SYNOPIS shows the syntax used by the command. DESCRIPTION provides a detailed description. •The SYNOPSIS follows certain conventions and rules which every user must understand: If the command argument is enclosed in rectangular brackets [ ], then it is optional; otherwise, the argument is required. The ellipsis (set of three dots) implies that there can be more instances of preceding word. The expression [ file . . . ] signifies more than one filename as argument. If you can find the character | in any of these areas, it means that only one of the options shown on either side of the pipe can be used.
  • 40. •The OPTIONS section list all the options used by the command. •The EXIT STATUS section lists possible error conditions and their numeric representation. •Example of a man page for wc command is shown below:
  • 41. KNOWING THE USER TERMINAL For knowing the user terminal have one command called tty (teletype) command. This command is simple and needs no arguments. $ tty /dev/pts/10 $tty output is /dev/pts/10 The terminal filename is 10 resident in the pts directory. This directory in turns is under the /dev directory. You can use tty in a shell script to control the behavior of the script depending on the terminal it is invoked from.
  • 42. The root login •The UNIX system provides a special login name for the exclusive use of the administrator; it is called root. •This account comes with every system. Its password is generally set at the time of installation of the system and has to be used on logging in: login: root password: ********* [Enter] #_ •The prompt of root is # •Once you log in as root, you are placed in root’s home directory. Depending on the system, this directory could be / or /root. •Most administrative commands are resident in /sbin and /usr/sbin.
  • 43. Becoming the super user: su command •Any user can acquire superuser status with the su command if he/she knows the root password. •For example, the user Juliet (with home directory /home/Juliet) becomes a superuser in this way: $ su Password: ********* [Enter] #_ • The current working directory doesn’t change, the # prompt indicates that Juliet now has the power of the superuser. • To be in root’s home directory on superuser login, use su –l. • Creating a User’s environment: su when used with a -, recreates the user’s environment without taking the login-password route For example : su – henry Temporarily creates henry’s environment. This mode is terminated by using exit.
  • 44. •The file is a container for information, we can treat it simply as sequence of character. •UNIX system has thousands of files. If you write a program, you add one more file to the system. When you compile it you add some more. Files grow rapidly, and if they are not organized properly, you will find it difficult to locate them. So UNIX has a file system (UFS) to manage or organizes its own files in directory. File is a collection of records. So, files are divided into three categories a. Ordinary file b. Directory file c. Device file
  • 45. a. Ordinary Files or regular files This is the most common file type. It contains only data as a stream of characters. An ordinary files itself divided into 2 types 1) Text file 2) Binary file 1) Text file: contains only printable characters, and you can often view the contents and make sense out of them. All C and Java files are example of text file. A text file contains lines of characters where every line is terminated with the newline character, also known as linefeed (LF) when you press Enter while inserting text, the LF character is appended to every line. You won’t see this character normally, but there is command (od) which can make it visible. 2) Binary file: it contains both printable and unprintable characters that cover the entire ASCII range(0 to 255).most UNIX commands are example of binary files, and the object code and executables that you produce by compiling C programs also binary files. Picture, sound and video files are binary files as well .
  • 46. b. Directory files A Directory Contains no data, but keeps some details of the files and subdirectories that it contains. The unix file system is organized with a number of directories and subdirectories, and you can also create them as and when you need.  A directory file contains an entry for every file and sub directory that it houses. If you have 20 files in a directory , there will be 20 entries in the directory.  Each entry has two components: The filename A unique Identification number for the file or directory( called the inode number)  A directory contains the filename but not the contents of file.  When you create or remove a file the kernel automatically updates its corresponding directory by adding or removing the enter i.e inode number associated with that file.
  • 47. c. Device files  Used to represent a real physical device such as a printer(printing a file & installing software from CD ROM or backing up files to tape), tape drive or terminal, used for Input/Ouput (I/O) operations.  Unix considers any device attached to the system to be a file - including your terminal:  By default, a command treats your terminal as the standard input file (stdin) from which to read its input  Your terminal is also treated as the standard output file (stdout) to which a command's output is sent.  stdin and stdout will be discussed in more detail later.  Two types of I/O: character and block  Device file names are generally found inside a single directory structure, /dev. Other file types Links: a system to make a file or directory visible in multiple parts of the system's file tree. (Domain) sockets: a special file type, similar to TCP/IP sockets, providing inter−process networking protected by the file system's access control. Named pipes: act more or less like sockets and form a way for processes to communicate with each other, without using network socket semantics.
  • 48. NAMING FILES OR WHAT’S IN A (FILE) NAME a. UNIX permits file names to use most characters, but avoid spaces, tabs and characters that have a special meaning to the shell, such as: & ; ( ) | ? ' " ` [ ] { } < > $ - ! / b. It is recommended that only the following characters be used in filenames. c. Alphabetic characters and numerals d. The period(.), the hyphen(-) and underscore(_) e. Case Sensitivity: uppercase and lowercase are not the same! These are three different files: NOVEMBER November november f. Length: can be up to 256 characters g. Extensions: may be used to identify types of files libc.a - archive, library file program.c - C language source file alpha2.f - Fortran source file xwd2ps.o - Object/executable code mygames.Z - Compressed file
  • 49. PARENT CHILD RELATIONSHIP/ UNIX FILE SYSTEM All files in UNIX are related to one another. The file system in unix is a collection of all ordinary, directory and device files and organized in a hierarchical structure as shown in below fig.
  • 50. • The implicit feature of every UNIX file system is that there is a top which serves as reference point for all files. This top is called root & is represented by a /(front slash). • Root is actually a directory. • The rootdirectory has a number of sub directories under it. These sub directories in turn have more sub directories and others files under them. • For instance bin and usr are two directories directly under root, while a second bin and kumar are sub directories under usr. • Every file apart from root must have a parent. Thus the home directory is the parent of kumar , while / is the parent of home and grandparent of kumar. • If you create a file login.sql under the kumar directory ,then kumar will be the parent of this file.
  • 51. The first group contains the files that are made available during system installation: /bin and /usr/bin: these are the directories where all the commonly used UNIX commands are found.  /sbin and /usr/sbin: If there’s a command that you can’t execute but the system administrator can execute, it would be probably in one of these directories.  /etc: this directory contains the configuration files of the system. You can change a very important aspect of system functioning by editing a text file in this directory. Your login name and password are stored in files /etc/passwd and etc/shadow  /dev: This directory contains all device files. These files don’t occupy space on disk. there could be more sub directories like pts, dsk and rdsk in this directory  /lib and /usr/lib: Contains shared library files and sometimes other kernel-related files.  /usr and /include: contains the standard header files used by C programs. The statement #include<stdio.h> used in most C programs referes to the file stdio.h in this directory.  /usr/share/man: this is where the man pages are stored. There are separate subdirectories here(like man1,man2 etc) that contains the pages for each section. For instance, the man page of ls can be found in /usr/share/man/man1 User also work with their own files, they write programs, send and receive mail and also create temporary files. These files are available in the second group shown below  /tmp: the directory where users are allowed to create temporary files. These files are wiped away regularly by the system  /var: The variable part of the file system. Contains all your print jobs and your outgoing and incoming mail.  /home: On many systems users are housed here. Kumar would have his home directory in /home/kumar
  • 52. HOME VARIABLE When log on to the system, UNIX automatically places you in a directory called the home directory. It is created by the system when user account is opened.  If you log in using the login name SJCIT , you will land up in a directory that could have the pathname /home/SJCIT The shell variable HOME known’s yours home directory $echo $HOME /home/SJCIT You will be doing much of your work in your home directory and subdirectories. Home variable: it is also called environment variables. Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer. Here $HOME is a environment variable it indicates the home directory of the current user: the default argument for the cd built-in command.
  • 53. PATH VARIABLE: The PATH environment variable is a colon-delimited list of directories that your shell searches through when you enter a command. Program files (executables) are kept in many different places on the Unix system. Your path tells the Unix shell where to look on the system when you request a particular program. To find out what your path is, at the Unix shell prompt echo $PATH  Your path will look something like the following. /usr2/username/bin:/usr/local/bin:/usr/bin:. You will see your username in place of username. Using the above example path, if you enter the ls command, your shell will look for the appropriate executable file in the following order: first, it would look through the directory /usr2/username/bin, then /usr/local/bin, then /usr/bin, and finally the local directory, indicated by the . (a period).
  • 54. ABSOLUTE PATHNAMES: If the first character of a pathname is / the files location must be determined with respect to root(/) . Such a pathname is called absolute pathname. cat /home/kumar When you have more than one / in a pathname for such / you have to descend one level in the file system. Thus Kumar is one level below home and two levels below root. When you specify a file y using front slashes to demarcate the various levels, you have a mechanism of identifying a file uniquely. No two files in a UNIX system can have same absolute pathnames. When you specify the date command, the system has to locate the file date from a list of directories specified in the PATH variable and then execute it.  However if you know the location of a command in prior, for example date is usually located in /bin or /usr/bin . Use absolute pathname i,e precede its name with complete path $/bin/date For example if you need to execute program less residing in /usr/local/bin you need to enter the absolute pathname $/usr/local/bin/less
  • 55. RELATIVE PATHNAMES  Pathnames that don’t begin with / specify locations relative to your current working directory.  Uses either the current or parent directory as reference and specifies path relative to it.  A relative pathname uses one of these cryptic symbols. . (a single dot)- this represents the current directory. .. (two dots) this represents the parent directory
  • 56. 1.Assume the current directory is /home/kumar/progs/data/text, using cd .. will move one level up $pwd /home/kumar/progs/data/text $ cd .. $pwd /home/kumar/progs/data 2.To move two levels up $pwd /home/kumar/progs $ cd ../.. $pwd /home 3. My present location is /etc/samba and now I want to change directory to /etc. Using relative path: $ cd .. Using absolute path: $cd /etc
  • 57. 4.My present location is /var/ftp/ and I want to change the location to /var/log Using relative path: cd ../log Using absolute path: cd /var/log 5.My present location is /etc/lvm and I want to change my location to /opt/oradba Using relative path: cd ../../opt/oradba Using absolute path: cd /opt/oradba
  • 58. DIRECTORY COMMANDS – PWD, CD, MKDIR, RMDIR COMMANDS pwd (PRINT WORKING DIRECTORY) (checking your current directory) As the name states, command ‘pwd‘ prints the current working directory or simply the directory user is, at present. It prints the current directory name with the complete path starting from root (/). This command is built in shell command and is available on most of the shell – bash, Bourne shell, ksh,zsh, etc. Basic syntax $pwd [option] If both ‘-L‘ and ‘-P‘ options are used, option ‘L‘ is taken into priority. If no option is specified at the prompt, pwd will avoid all system links, i.e., take option ‘-P‘ into account.
  • 59. cd: CHANGING THE CURRENT DIRECTORY The cd command, which stands for "change directory", changes the shell's current working directory. The cd command is one of the commands you will use the most at the command line in UNIX. It allows you to change your working directory. You use it to move around within the hierarchy of your file system. Example- When used with an argument it changes the current directory to the directory specified as argument for example assume acsce is a directory under user directory vinutha. To change from vinutha directory to acsce directory , issue the command as follows $pwd /home/ acsce $cd vinutha $pwd /home/ acsce / vinutha
  • 60. EXAMPLE-2: When cd used without arguments: cd when used without arguments reverts to home directory $pwd /home/kumar/acsce $cd cd without argument will change directory from gmit to its home directory Kumar $pwd /home/kumar EXAMPLE-3: If your present working directory is /home/Kumar and you need to switch to /bin directory directly, use absolute pathname i.e /bin wd cd command $pwd /home/kumar $cd /bin $pwd /bin
  • 61. mkdir: "making directory". mkdir is used to create directories on a file system.  If the specified DIRECTORY does not already exist, mkdir creates it.  More than one DIRECTORY may be specified when calling mkdir. mkdir syntax mkdir [OPTION ...] DIRECTORY ... Ex 6.3.1: To create a directory named acsce, issue the following command. $mkdir acsce acsce directory is created under present working directory. Assume that pwd is /home/kumar , then acsce directory is created under kumar directory. Ex 6.3.2: To create three directories at a time, named patch, dbs, doc, pass directory names as arguments. $mkdir patch dbs doc Ex 6.3.3:To create a directory tree: To create a directory named acsce and create two subdirectories named cse and ise under acsce, issue the command. acsce is a parent directory. $mkdir parent directory sub-directories $mkdir acsce acsce/cse acsce/ise
  • 62. Ex 6.3.4: Error while creating a directory tree $mkdir acsce/cse gmit/ise mkdir: Failed to make a directory “acsce/cse”; no such file or directory mkdir: Failed to make a directory “acsce/ise”; no such file or directory Error is due to the fact that the parent directory named gmit is not created before creating sub directories cse and ise. Ex 6.3.5: $mkdir test mkdir: Failed to make directory “test”; Permission denied. This can happen due to: a. The directory named test may already exist b. There may be an ordinary file by the same name in the current directory. c. The permissions set for the current directory do not permit the creation of files and directories by the user.
  • 63. rmdir: REMOVING DIRECTORIES The rmdir utility removes the directory entry specified by each directory argument, provided the directory is empty. Ex 6.4.1: $rmdir progs removes the directory named progs Arguments are processed in the order given. To remove both a parent directory and a subdirectory of that parent, the subdirectory must be specified first, so the parent directory is empty when rmdir tries to remove it. The reverse logic of mkdir is applied. $rmdir subdirectories parent directory $rmdir acsce/cse acsce/ise acsce You cant delete a directory with rmdir unless it is empty.In this example gmit directory cannot be removed until the sub directories cse and ise are removed. You cant remove a sub directory unless you are place in a directory which is hierarchically above the one you have chosen to remove.