0% found this document useful (0 votes)
33 views

Unit 2

Uploaded by

patelpreet8686
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Unit 2

Uploaded by

patelpreet8686
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Unit-2: Overview of Unix OS

2.1 Logging in & out


Logging in
Logging in to a UNIX system requires two pieces of information: A username, and
a password. When you sit down for a Unix session, you are given a login prompt
that looks like this:
Login:
Type your username at the login prompt, and press the return key. The system will
then ask you for your password. When you type your password, the screen will not
display what you type.
Your username
Your username is assigned by the person who creates your account. The standard
username is the first four letters of your last name concatenated with the first four
letters of your first name.

Your username must be unique on the system where your account exists since it is
the means by which you are identified on the system.

Your password
When your account is created, a password is assigned. The first thing you should
do is change your password, using the passwd utility. To change your password,
type the command
passwd
After you have logged in. The system will ask for your old password, to prevent
someone else from sneaking up, and changing your password. Then it will ask for
your new password. You will be asked to confirm your new password, to make
sure that you didn't mistype. It is very important that you choose a good password,
so that someone else cannot guess it. Here are some rules for selecting a good
password:

 Do not use any part of your name, your spouse's name, your child's name,
your pet's name, or anybody's name. Do not use any backward spellings of
any name, either.
 Do not use an easily-guessable number, like your phone number, your social
security number, your address, license plate number, etc.
 Do not use any word that can be found in an English or foreign-language
dictionary.
1
Unit-2: Overview of Unix OS

 Do not use all the same letter, or a simple sequence of keys on the keyboard,
like qwerty.
 Do use a mix of upper-case and lower-case letters, numbers, and control
characters.
 Do use at least six characters.

If you have accounts on multiple machines, use a different password on each


machine. Do not choose a password that is so difficult to remember that you must
write it down.

logout

When you finish using the shell, type the exit or logout command. This will
either display a new login prompt or close the terminal emulator window. If you
are logged in remotely to a server, this will break your connection. If you are
logged in physically on a large UNIX system, this will prevent someone else from
abusing your account.

When you finish using the shell, type the exit or logout command. This will
either display a new login prompt or close the terminal emulator window.

Some of the possible variations of this command include: bye, exit, lo, logout,
and quit.

Typing CtrlL-D (holding down the CONTROL key and the D key at the same
time) will also log you out of most shells. The Ctrl-D tells the shell it has reached
the end-of-file (EOF). Because the shell is a filter and filters terminate when EOF
is reached, the shell terminates and you log off the system or return to the parent
process.

While it might not be a big deal to skip this step on a single user computer that
you never leave unattended, forgetting to logout from a remote server is a serious
security hole. If you leave your computer or terminal unattended, someone else can
sit down and gain access to all of your files, including the ability to read, modify,
or delete them. The imposter can send spam emails from your user ID. The
imposter can even use your computer or account to attempt to hack or damage or
break into any system in the world from your user ID. If this occurs from a school
or business account, you will be responsible for any damage done.

Most modern systems accept either logout or exit.

2
Unit-2: Overview of Unix OS

2.2 I node and File Structure


i-node

3
Unit-2: Overview of Unix OS

A file system relies on data structures about the files, beside the file content. The
former is called metadata—data that describes data. Each file is associated with an
inode, which is identified by an integer number, often referred to as an i-number or
inode number.
Inodes store information about files and directories (folders), such as file
ownership, access mode (read, write, execute permissions), and file type. On many
types of file system implementations, the maximum number of inodes is fixed at
file system creation, limiting the maximum number of files the file system can
hold. A typical allocation heuristic for inodes in a file system is one percent of total
size.
Regular files must have the following attributes:
• The size of the file in bytes.
• Device ID (this identifies the device containing the file).
• The User ID of the file's owner.
• The Group ID of the file.
• The file mode which determines the file type and how the file's owner, its group,
and others can access the file.
• Additional system and user flags to further protect the file (limit its use and
modification).
• Timestamps telling when the inode itself was last modified (ctime, inode change
time), the file content last modified (mtime, modification time), and last accessed
(atime, access time).
• A link count telling how many hard links point to the inode.
• Pointers to the disk blocks that store the file's contents The stat system call
retrieves a file's inode number and some of the information in the inode.

Above to all inode has repository of data blocks.

4
Unit-2: Overview of Unix OS

• With 8 KB data blocks, if the file is 96 KB or smaller, then it uses 12 blocks


or less on disk, and all those block addresses are stored directly in the inode itself.
• When the file grows bigger, the disk driver allocates a single indirect block,
and records that in the inode. When the driver needs to get a block, it reads the
indirect block into memory, and then finds the address for the block it needs from
the indirect block. Thus, it requires (nominally) two reads to get to the data, though
of course the indirect tends to be cached in memory.
• With an 8 KB block size and 4-byte disk addresses, you can fit 2048 disk
addresses in the single indirect block. So, for files from 96 KB + 1 byte to 16 MB
or so, there is only a single indirect block.
• If a file grows still bigger, then the driver allocates a double indirect block.
Each pointer in the double indirect block points to a single indirect block. So, you
can have 2048 more indirect blocks, each of which can effectively point at 16 MB,
leading to files of up to 32 GB being storable.
• If a file grows still larger, then the driver allocates a triple indirect block.
Each of the 2048 pointers in a triple indirect block points to a double block. So,
under the 32-bit addressing scheme with 32-bit addresses, files up to about 64 TB
could be addressed. Except that You’ve run out of disk addresses before that (32
TB maximum because of the 32-bit addresses to 8 KB blocks).

2.3 File System Structure and Features

5
Unit-2: Overview of Unix OS

The UNIX file system is organized as a hierarchy of directories starting from a


single directory called root which is represented by a / (slash). Imagine it as being
similar to the root system of a plant or as an inverted tree structure.
Immediately below the root directory are several system directories that contain
information required by the operating system. The file holding the UNIX kernel is
also here.
• UNIX system directories
• Home directory
• Pathnames

FILE SECURITY
UNIX has 3 levels of security.
1st level username and password for login.
2nd level is read, write and execute permission for the file.
At 3rd level user can encrypt the file.
Task: Encrypt the original file called my.txt
Type the command as follows: $ cat my.txt | crypt > my.cpy Output:
Enter key:123
This will create an encrypted form of my.txt file, and store it in the file my.cpy.
Supported on BSD systems only.

Types of files in unix

6
Unit-2: Overview of Unix OS

File Types in Unix - Ordinary or Regular Files, Directories, Device (Special)


Files, Links, Named Pipes, and Sockets
Ordinary or Regular Files A large majority of the files found on UNIX and
Linux systems are ordinary files. Ordinary files contain ASCII (human-readable)
text, executable program binaries, program data, and more. Directories A
directory is a binary file used to track and locate other files and directories. The
binary format is used so that directories containing large numbers of filenames can
be search quickly. Device (Special) Files

7
Unit-2: Overview of Unix OS

Device or special files are used for device I/O on UNIX and Linux systems. They
appear in a file system just like an ordinary file or a directory. On UNIX systems
there are two flavors of special files for each device, character special files and
block special files. Linux systems only provide one special file for each device.
When a character special file is used for device I/O, data is transferred one
character at a time. This type of access is called raw device access. When a block
special file is used for device I/O, data is transferred in large fixed-size blocks.
This type of access is called block device access. Links A link is a tool used for
having multiple filenames that reference a single file on a physical disk. They
appear in a file system just like an ordinary file or a directory. Like special files,
links also come in two different flavors. There are hard links and symbolic links.
Hard links do not actually link to the original file. Instead they maintain their own
copy of the original file's attributes (i.e. location on disk, file access permissions,
etc.). If the original file is deleted, its data can still be accessed using the hard link.
On the other hand, symbolic links contain a pointer, or pathname, to the original
file. If the original file is deleted, its data can no longer be accessed using the
symbolic link, and the link is then considered to be a stale link. Named Pipes
Named pipes are tools that allow two or more system processes to communicate
with each other using a file that acts as a pipe between them. This type of
communication is known as interprocess communication or IPC for short.

8
Unit-2: Overview of Unix OS

9
Unit-2: Overview of Unix OS

Sockets: Sockets are also tools used for interprocess communication. The
difference between sockets and pipes is that sockets will facilitate communication
between processes running on different systems, or over the network. With so
many different types of files, it's often wise to identify a file's type before
performing any operation with it. The ls -l command and the file command are
useful for determining file types. Consider the long listing of the livefirelabs1 file:
-rw-rw-r-- 1 student1 student1 0 Jun 27 18:55 livefirelabs1
The first character of the first field indicates the file type. In this example, the first
character is a - (hyphen) indicating that livefirelabs1 is an ordinary or regular file.
Consider the long listing of the live1 file:
lrwxrwxrwx 1 student1 student1 13 Jun 27 17:57 live1 -> livefirelabs1
The first character of the first field is the letter l indicating live1 is a symbolic link.
The following is a table listing what characters represent what types of files:
- Ordinary or Regular File d Directory c Character special file b Block special file l
Symbolic link p Named pipe s Socket
The file command is also helpful for determining file types. The syntax for this
command is:
$ file filename
File System
In the original Unix file system, Unix divided physical disks into logical disks
called partitions. Each partition is a standalone file system. We will use the term
``file system'' when referring to a single partition.
Each disk device is given its own major device number, and each partition has an
associated minor device number which the device driver uses to access the raw file
system.
The major/minor device number combination serves as a handle into the device
switch table. That is, the major number acts as an index, and the minor number is
passed as an argument to the driver routines so that they can recognize the specific
instance of a device.
Each filesystem contains:

1 In the original Unix file system, Unix divided physical disks into logical disks
called partitions. Each partition is a standalone file system. We will use the term ``file
system'' when referring to a single partition.

Each disk device is given its own major device number, and each partition has an
associated minor device number which the device driver uses to access the raw file
system.

10
Unit-2: Overview of Unix OS

The major/minor device number combination serves as a handle into the device switch
table. That is, the major number acts as an index, and the minor number is passed as
an argument to the driver routines so that they can recognize the specific instance of a
device.

Each filesystem contains:

1.
a boot block located in the first few sectors of a file system. The boot block
contains the initial bootstrap program used to load the operating system.

Typically, the first sector contains a bootstrap program that reads in a larger
bootstrap program from the next few sectors, and so forth.

2.
a super block describes the state of the file system: the total size of the
partition, the block size, pointers to a list of free blocks, the inode number of
the root directory, magic number, etc.
3.
a linear array of inodes (short for ``index nodes''). There is a one to one
mapping of files to inodes and vice versa. An inode is identified by its ``inode
number'', which contains the information needed to find the inode itself on the
disk

Thus, while users think of files in terms of file names, Unix thinks of files in
terms of inodes.

Thus, while users think of files in terms of file names, Unix thinks of files in terms
of inodes.
4.
data blocks: blocks containing the actual contents of files
---------------------------------------------------------------

| B. B. | S. B. | Inodes | | | ... | Data Blocks |

---------------------------------------------------------------
An inode is the ``handle'' to a file and contains the following information:
• • file ownership indication
• • file type (e.g., regular, directory, special device, pipes, etc.)
• • file access permissions. May have setuid (sticky) bit set.
• • time of last access, and modification

11
Unit-2: Overview of Unix OS

number of links (aliases) to the file


• • pointers to the data blocks for the file
• • size of the file in bytes (for regular files), major and minor device numbers
for special devices.

An integral number of inodes fits in a single data block.


Information the inode does not contain:
• path (short or full) name of file
Features of Unix File System
Unix file system is a logical method of organizing and storing large amounts of
information in a way that makes it easy to manage. A file is a smallest unit in which
the information is stored. Unix file system has several important features. All data in
Unix is organized into files. All files are organized into directories. These directories
are organized into a tree-like structure called the file system.
Files in Unix System are organized into multi-level hierarchy structure known as a
directory tree. At the very top of the file system is a directory called “root” which is
represented by a “/”. All other files are “descendants” of root.

12
Unit-2: Overview of Unix OS

Directories or Files and their description –


 / : The slash / character alone denotes the root of the filesystem tree.
 /bin : Stands for “binaries” and contains certain fundamental utilities,
such as ls or cp, which are generally needed by all users.
 /boot : Contains all the files that are required for successful booting
process.
 /dev : Stands for “devices”. Contains file representations of peripheral
devices and pseudo-devices.
 /etc : Contains system-wide configuration files and system databases.
Originally also contained “dangerous maintenance utilities” such as
init,but these have typically been moved to /sbin or elsewhere.
 /home : Contains the home directories for the users.
 /lib : Contains system libraries, and some critical files such as kernel
modules or device drivers.
 /media : Default mount point for removable devices, such as USB
sticks, media players, etc.
 /mnt : Stands for “mount”. Contains filesystem mount points. These are
used, for example, if the system uses multiple hard disks or hard disk
partitions. It is also often used for remote (network) filesystems, CD-
ROM/DVD drives, and so on.
 /proc : procfs virtual filesystem showing information about processes
as files.
 /root : The home directory for the superuser “root” – that is, the system
administrator. This account’s home directory is usually on the initial
filesystem, and hence not in /home (which may be a mount point for
another filesystem) in case specific maintenance needs to be performed,
during which other filesystems are not available. Such a case could
occur, for example, if a hard disk drive suffers physical failures and
cannot be properly mounted.
 /tmp : A place for temporary files. Many systems clear this directory
upon startup; it might have tmpfs mounted atop it, in which case its
contents do not survive a reboot, or it might be explicitly cleared by a
startup script at boot time.
 /usr : Originally the directory holding user home directories,its use has
changed. It now holds executables, libraries, and shared resources that
are not system critical, like the X Window System, KDE, Perl, etc.
However, on some Unix systems, some user accounts may still have a
home directory that is a direct subdirectory of /usr, such as the default
as in Minix. (on modern systems, these user accounts are often related
to server or system use, and not directly used by a person).
13
Unit-2: Overview of Unix OS

 /usr/bin : This directory stores all binary programs distributed with the
operating system not residing in /bin, /sbin or (rarely) /etc.
 /usr/include : Stores the development headers used throughout the
system. Header files are mostly used by the #include directive in
C/C++ programming language.
 /usr/lib : Stores the required libraries and data files for programs stored
within /usr or elsewhere.
 /var : A short for “variable.” A place for files that may change often –
especially in size, for example e-mail sent to users on the system, or
process-ID lock files.
 /var/log : Contains system log files.
 /var/mail : The place where all the incoming mails are stored. Users
(other than root) can access their own mail only. Often, this directory is
a symbolic link to /var/spool/mail.
 /var/spool : Spool directory. Contains print jobs, mail spools and other
queued tasks.
 /var/tmp : A place for temporary files which should be preserved
between system reboots.

2.4 Booting Sequence & init process


The bootup process (or "boot sequence") varies in details among systems, but can
be roughly divided into phases controlled by the following components:

1.
hardware
2.
operating system (OS) loader
3.
kernel
4.
root user-space process (init and inittab)
5.
boot scripts

Each of these is described below in more detail.

14
Unit-2: Overview of Unix OS

Hardware
After power-on or hard reset, control is given to a program stored in read-only
memory (normally PROM); for historical reasons involving the personal computer,
this program is often called "the BIOS".

This program normally performs a basic self-test of the machine and accesses
nonvolatile memory to read further parameters. This memory in the PC is battery-
backed CMOS memory, so most people refer to it as "the CMOS"; outside of the
PC world, it is usually called "the NVRAM" (nonvolatile RAM).

The parameters stored in the NVRAM vary among systems, but as a minimum,
they should specify which device can supply an OS loader, or at least which
devices may be probed for one; such a device is known as "the boot device". The
hardware boot stage loads the OS loader from a fixed position on the boot device,
and then transfers control to it.

Note:
The device from which the OS loader is read may be attached via a network,
in which case the details of booting are further specified by protocols such as
DHCP, TFTP, PXE, Etherboot, etc.
OS loader
The main job of the OS loader is to locate the kernel on some device, load it,
and run it. Most OS loaders allow interactive use, in order to enable
specification of an alternative kernel (maybe a backup in case the one last
compiled isn't functioning) and to pass optional parameters to the kernel.

In a traditional PC, the OS loader is located in the initial 512-byte block of the
boot device; this block is known as "the MBR" (Master Boot Record).

In most systems, the OS loader is very limited due to various constraints. Even
on non-PC systems, there are some limitations on the size and complexity of
this loader, but the size limitation of the PC MBR (512 bytes, including the
partition table) makes it almost impossible to squeeze much functionality into
it.

Therefore, most systems split the role of loading the OS between a primary OS
loader and a secondary OS loader; this secondary OS loader may be located
within a larger portion of persistent storage, such as a disk partition.

15
Unit-2: Overview of Unix OS

In Linux, the OS loader is often either lilo(8) or grub(8).

Kernel
When the kernel is loaded, it initializes various components of the computer
and operating system; each portion of software responsible for such a task is
usually consider "a driver" for the applicable component. The kernel starts the
virtual memory swapper (it is a kernel process, called "kswapd" in a modern
Linux kernel), and mounts some filesystem at the root path, /.

Some of the parameters that may be passed to the kernel relate to these
activities (for example, the default root filesystem can be overridden); for
further information on Linux kernel parameters.

Only then does the kernel create the initial userland process, which is given the
number 1 as its PID (process ID). Traditionally, this process executes the
program /sbin/init, to which are passed the parameters that haven't already been
handled by the kernel.

Root user-space process


Note:
The following description applies to an OS based on UNIX System V
Release 4. However, a number of widely used systems have adopted a
related but fundamentally different approach known as systemd (1), for
which the bootup process is detailed in its associated bootup(7).

When /sbin/init starts, it reads /etc/inittab for further instructions. This file
defines what should be run when the/sbin/init program is instructed to enter
a particular run-level, giving the administrator an easy way to establish an
environment for some usage; each run-level is associated with a set of
services (for example, run-level S is single-user mode, and run-
level 2 entails running most network services).

The administrator may change the current run-level via init (1), and query
the current run-level via runlevel(8).

However, since it is not convenient to manage individual services by editing


this file, /etc/inittab only bootstraps a set of scripts that actually start/stop the
individual services.

16
Unit-2: Overview of Unix OS

Boot scripts
Note:
The following description applies to an OS based on UNIX System V
Release 4. However, a number of widely used systems (Slack ware Linux,
FreeBSD, OpenBSD) have a somewhat different scheme for boot scripts.

For each managed service (mail, nfs server, cron, etc.), there is a single
startup script located in a specific directory (/etc/init.d in most versions of
Linux). Each of these scripts accepts as a single argument the word
"start" (causing it to start the service) or the word "stop" (causing it to
stop the service). The script may optionally accept other "convenience"
parameters (e.g., "restart" to stop and then start, "status" to display the
service status, etc.). Running the script without parameters displays the
possible arguments.

Sequencing directories
To make specific scripts start/stop at specific run-levels and in a specific
order, there are sequencing directories, normally of the form /etc/rc[0-
6S].d. In each of these directories, there are links (usually symbolic) to
the scripts in the /etc/init.d directory.

A primary script (usually /etc/rc) is called from inittab (5); this primary
script calls each service's script via a link in the relevant sequencing
directory. Each link whose name begins with 'S' is called with the
argument "start" (thereby starting the service). Each link whose name
begins with 'K' is called with the argument "stop" (thereby stopping the
service).

To define the starting or stopping order within the same run-level, the
name of a link contains an order-number. Also, for clarity, the name of
a link usually ends with the name of the service to which it refers. For
example, the link /etc/rc2.d/S80sendmail starts the sendmail service on
runlevel 2. This happens after /etc/rc2.d/S12syslog is run but
before /etc/rc2.d/S90xfs is run.

To manage these links is to manage the boot order and run-levels; under
many systems, there are tools to help with this task (e.g., chkconfig (8)).

17
Unit-2: Overview of Unix OS

Boot configuration
A program that provides a service is often called a "daemon". Usually, a
daemon may receive various command-line options and parameters. To
allow a system administrator to change these inputs without editing an
entire boot script, some separate configuration file is used, and is located
in a specific directory where an associated boot script may find it
(/etc/sysconfig on older Red Hat systems).

In older UNIX systems, such a file contained the actual command line
options for a daemon, but in modern Linux systems (and also in HP-UX),
it just contains shell variables. A boot script in /etc/init.d reads and
includes its configuration file (that is, it "sources" its configuration file)
and then uses the variable values.

Init process
The kernel, once it is loaded, finds init in sbin and executes it.
When init starts, it becomes the parent or grandparent of all of the processes that
start up automatically on your Linux system. The first thing init does, is reading its
initialization file, /etc/inittab. This instructs init to read an initial configuration
script for the environment, which sets the path, starts swapping, checks the file
systems, and so on. Basically, this step takes care of everything that your system
needs to have done at system initialization: setting the clock, initializing serial
ports and so forth.
Then init continues to read the /etc/inittab file, which describes how the system
should be set up in each run level and sets the default run level. A run level is a
configuration of processes. All UNIX-like systems can be run in different process
configurations, such as the single user mode, which is referred to as
run level 1 or run level S (or s). In this mode, only the system administrator can
connect to the system. It is used to perform maintenance tasks without risks of
damaging the system or user data. Naturally, in this configuration we don't need to
offer user services, so they will all be disabled.
Another run level is the reboot run level, or run level 6, which shuts down all
running services according to the appropriate procedures and then restarts the
system.
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.

18
Unit-2: Overview of Unix OS

# Default run level. The run levels are:


# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS
# (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)

2.5 File Access Permissions


owner can change permission for file or directory.

For this chmod command is used. Following table is used by chmod


command.

category permission type

u=owner r=read permission + assign permission

g=group w=write " - revoke permission

o=others x=execute " =absolute permission

a=all

+,- are used for relative permission. Relative permission is permission


which do not affect

Other permissions but = is used for absolute permission and it affects


other permissions.

$ls -l b2

-rw-r--r--

Above is default permission for file


19
Unit-2: Overview of Unix OS

Default permission for owner= read, write

" " " group=read

" " " others=read

$chmod ug+x b2

above command gives execute permission to owner and group

$chmod g+w b2

above command give write permission to group

after issuing above commands file's permission will be

-rwxrw-r-x.

$chmod a-x b2

above command will revoke execute permission from everybody.

now file's permission will be

-rw-rw-r--

$chmod u=x b2

above command will assign execute permission to owner but will revoke
every other

20
Unit-2: Overview of Unix OS

permission from owner.

now file's permission will be

---xrw-r--

$chmod go=x b2

above command will assign execute permission to group and others but
every other

permission from group and others will be revoked. Now file's permission
will be

---x--x--x

$chmod a=r b2

now file's permission will be

-r--r--r--

OCTAL codes can be used for absolute permission.

Umask command
umask, as the man page says, stands for User file creation mask which is used for
determining the default permission for a new file creation. The new file creation
could either be a file creation through a normal process or a file copy. umask
command is a shell built-in meaning it is an internal command.

The three file permission attributes are read, write and execute. These 3 are
mapped to octal values as shown below:
read -4
write -2

21
Unit-2: Overview of Unix OS

execute - 1

In UNIX, the default file creation value is 666. 6 is 4+2(read + write). Permission
666 means 6 for the User, 6 for the group and 6 for others. Hence, a new file
creation by default is meant to have read and write permission for User, group and
others. This is the place where the umask comes into the picture. It is a kind of
filter wherein we can choose to retain or block some of the default permissions
from being applied on the file.

Say, the umask value is 0022. umask is by default displayed in Octal form, and
hence the first 0 in the umask value is the indication for octal value. So, the actual
umask is 022. This value together with the default file value(666) decides the final
permission to be given to the file.

Assume we create a file say "file1". The permissions given for this file will be the
result coming from the substraction of the umask from the default value :

Default: 666
umask : 022
---------------
Result : 644

644 is the permission to be given on the file "file1". 644 means read and write for
the User(644), read only for the group(644) and others(644).

$ touch file1

$ ls -l file1

-rw-r--r-- 1 guru None 0 Apr 22 18:53 file1

The same rule is applied while creating a directory as well.


But for directories, the umask value is subtracted from 777.
22
Unit-2: Overview of Unix OS

Default:777
Umask:022
_________________
Result: 755
That means owner will have read, write, execute rights, group and others will
have read, execute permission on newly created directories.

Let us have some FAQ:

1. What is umask?
umask is a number which defines the default permissions which are not to be
given on a file. A umask of 022 means not to give the write permission to the
group(022) and others(022) by default.

2. How to find out the umask value?

$ umask

0022

The option -S gives in more readable format.

$ umask -S

u=rwx,g=rx,o=rx

This means umask, at the max, allows all permissions for the user, read and
execute alone for the group and others.

3. How to set the umask value?

23
Unit-2: Overview of Unix OS

$ umask 033

The same can be given in this below form as well:

$ umask u=rwx,g=r,o=r

4. How to set this umask permanently for a user?


To set this value permanently for a user, it has to be put in the
appropriate profile file which depends on the default shell of the user.

5. Does this umask come into picture while copying a file?


Yes, during the copying of a file also umask is used. The new file created using
the copy command also follows the same umask rules as above.

6. Can we retain the permission of the source file while copying a file?
Yes, we can retain the permission of the source file using the cp command. As
shown in the example 4 of one of our earlier articles on cp command, the mode of
the source file can be retained.

7. Who can set the umask value?


It can be set by the root user which will be applicable across the system. Also,
a given user can override the umask value by having his own setting in his/her
profile file.

A umask value of 002 is commonly used by people who are working on group
projects. If you create a file with your umask set to 002, anyone in the file's group
will be able to read or modify the file. Everybody else will only be allowed to read
it:

When one creates file


0666 default file-creation mode
(0002) umask
0664 resultant mode , default permissions
For user read and write, for group read and write for others only read permission
0777 default directory-creation mode

24
Unit-2: Overview of Unix OS

(0002) umask
0775 resultant mode, default permissions
Read+write+execute for user, read+write +execute for group, read+execute for
others.

25

You might also like