0% found this document useful (0 votes)
22 views6 pages

Unix Unit-2

Fogg DC NJ hcfchgfddfbgg

Uploaded by

ishowspeed5519
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views6 pages

Unix Unit-2

Fogg DC NJ hcfchgfddfbgg

Uploaded by

ishowspeed5519
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Types of user:

1. The ower of file(user)


2. The users who belong to the same group as the file(group)
3. Everyone else(other)

Creating users:
With useradd command you can create a user. To create a new user account, invoke the
useradd command followed by the name of the user.

For example to create a new user named username you would run:

$ sudo useradd username

Only root or users with sudo (super-user do) privileges can use the useradd command to
create new user account.
To log in as the newly created user, you need to set the user password. To do that run the
passwd command followed by the username:
$sudo passwd username

User management command:

Accessing a user configuration file


$cat /etc/passwd

This command prints the data of the configuration file. This file contains information
about the user in the format.

Change the user ID for a user:

Usermod -u new_id username

This command can change the user ID of a user. The user with the given username will
be assigned with the new ID given in the command and the old ID will be removed.

Example: $ sudo usermod -u 1982 test

Modify the group ID of a user:

usermod -g new_group_id username


This command can change the group ID of a user and hence it can even be used to move a
user to an already existing group. It will change the group ID of the user whose username is
given and sets the group ID as the given new_group_id.
Example: $ sudo usermod -g 1005 test
Change the user login name:

You can change the user login name using usermod command.
The below command is used to change the login name of the user.
The old login name of the user is changed to the new login name provided.
sudo usermod -l new_login_name old_login_name

Delete a user name:

The below command deletes the user whose username is provided in the command. Make
sure that the user is not part of a group. If the user is part of a group then it will not be
deleted directly, hence we will have to first remove him from the group and
then we can delete him.

userdel -r username

UNIX FILE SYSTEM:

Introduction:-

A file is one in which data can be stored.It is a sequence of bits,bytes or lines and stored on
a storage device like a disk.Inunix everything is stored in terms of files.It could be a
program,an executable code,a file,a set of instructions,a database,a directory or a
subdirectory. A unix file is a tool or an application that defines the structure of the file and
its format.

Unix Filenames:

Unix is case sensitive! So a file named my data. Txt is different from mydata.txt
which is again different from mydata.txt. Unix filenames contain only letters,numbers and
the_(underscore)&.(dot)
characters.All other characters should be avoided. The /(slash) characters is
especially important/since it is used to designate subdirectories.
It is also possible to have additional dots in the filename.
The part of the name that follows the dot is often used to designate the type of file.
Files that end in.TXT are text files.
Files thatend in.C are source code in the ‘C’ language.
Files that end in.HTML files for the web.
But this is just a convention and not a rule enforced by the operating system.this
is a good and sensible convention which you should follow.
Most UNIX system allow a maximum of 14 characters as the length of a
filename. However it depends on the UNIX variant used.

FILE SYSTEM:
The unix file system is organized as a hierarchical tree structure.
The structure of a simple unix file system divided into 4 parts.
1. The Boot block
2. The Super block
3. The Inode block
4. The Data blocks
1) The Boot Block
The boot block is located at the beginning of the file system.
It can be accessed with minimal code incorporated in the computer’s ROM bios.
It contains the initial bootstrap program used to load the os.
It is usually a part of the disk label, aspecial set of blocks containing information on the disk
layout.
2) The Super Block
It contains statistical information to keep track of the entire file system. Whenever
disk manipulation is required,the super block is accessed.
The Super Block contains the following information:
1. Size of the file system: This is the storage size of the device.
2. List of storage blocks: The storage space is divided up into a series of standard
size blocks.
3. Number of free blocks on the file system.
4. A list of free blocks with their location.
5. Index to next free block on the list.
6. A list of free inodes.
3) The Inode Block
Information about each file in the file system is a special kernel structure called an
inode.
It contains a pointer to the disk blocks containing the data in the file,information
such as type of file,permission bits,the owner and group,file size,file modification
and so on.
The name of each file is listed in the directory the file is associated with.A directory
is special type of containing a list of filenames and associated inodes.
When a user attempts to access a given file by name,the name is looked up in the
directory. Where the corresponding inode is found.
An inode for a file contains the following information
File owerid : It is the numeric id used in the password file to
uniquely identify a user on the system.
Group id (GID) :This identifies a group that can be granted special
access by the ower.
File type :It indicates whether inode represents a
file,adirectory,aFIFO,character device.
4) Data Block
It contain the actual data contained in the files.
These blocks follows the inode table and occupy most of the storage device
space.
It allotted to one file cannot be allotted to another file, unless the two files
are linked.
Types of Files:

The unixos is built around the concept of the a file system which is which is used to store
all of information. Including the operating sysem kernel itself.
There are 4 types of files:
1. Ordinary or Regular files
2. Directory files
3. Device files or special files
4. Hidden files

1. Regular or ordinary files: It can contain text, data,or program information, files
cannot contain other files or directories. Instead use the underscore(’_’) symbol.it is
ordinary file.
An ordinary file can be of 2 types.
i. Text file
ii. Binary file
I. Text File: A text file contains only printable characters.it contains line
of character, each line terminated by a newline character .
Ex:text files include c and Java program ,shell and perl scripts.
II. Binary File:a binary file contains both printable and unprintable
character(0 to 255 ASCII code).
Ex:binary files include unix command ,object code of c programs
,pictures,sound,and video files.

2. Directory files : Directories are containers or folders that holdfiles,and other


directories.Directories can point to other directories which are known as Sub
directories.The directories generally contains files and other sub directories along with
their
link information . normally a directory contains 2 pieace of information.
i. The file name
ii. A unique identification number.
When a user creates or remove a file ,the kernel updates the
corresponding directory by adding or removing the inode number and
filesname associated with the file.

3.Device files :To provide applications, with easy access to hardware devices.UNIX
allows them to be used in much the same way as ordinary files. The video screen of
your pc,RAM,disk,input ports and other such devices are usually accessed through
device file.
Two types of device files in unix
Block-oriented :Block-oriented devices which transfer data in blocks.
EX: Hard disk
Character-oriented: Character oriented devices that transfer data on a byte -bybyte
basis(eg.modems,printers and networks).
2 Hidden files :The filename can begin with a dot character is called hidden file.

File Quotas:
The user and group quotas provide the mechanisms by which the amount of space used
by a single user or all users within a specific group can be limited to a value defined by
the administrator.
Quotas operate around two limits that allow the user to take some action if the amount
of space or number of disk blocks start to exceed the administrator defined limits −
Soft Limit − If the user exceeds the limit defined, there is a grace period that allows
the user to free up some space.
Hard Limit − When the hard limit is reached, regardless of the grace period, no
further files or blocks can be allocated.
There are a number of commands to administer quotas −
Sr.No. Command Description
1 quota Displays disk usage and limits for a user of group
2 edquota Users or Groups quota can be edited using this command
3 quotacheck Scans a filesystem for disk usage, creates and repairs quota files
4 setquota This is a command line quota editor
5 quotaon This announces to the system that disk quotas should be
6 quotaoff This announces to the system that disk quotas should be disabled
7 repquota This prints a summary of the disc usage and quotas

Links (hard links, symbolic links):


A link in UNIX is a pointer to a file. Links in UNIX are pointers pointing to a file or a
directory. Creating links is a kind of shortcuts to access a file.
There are two types of links :
1. Soft Link or Symbolic links
2. Hard Links

1. Hard Links :
Each hard linked file is referred to the same physical file location. Hard links are
flexible and remain linked even if the original or linked files are moved throughout the
file system.

Links have actual file contents. Removing any link, just reduces the link count, but
doesn’t affect other links.
Even if we change the filename of the original file then also the hard links properly
work.
We cannot create a hard link for a directory to avoid recursive loops.
If original file is removed then the link will still show the content of the file.
The size of any of the hard link file is same as the original file and if we change the
content in any of the hard links then size of all hard link files are updated.
The disadvantage of hard links is that it cannot be created for files on different file
systems and it cannot be created for special files or directories.
Command to create a hard link is:
$ ln [original filename] [link name]

2. Soft Links :
A soft link is similar to the file shortcut feature which is used in Windows Operating
systems.
As similar to hard links, any changes to the data in either file is reflected in the other.
Soft links can be linked across different file systems, although if the original file is
deleted or moved, the soft linked file will not work correctly (called hanging link).
Soft Link contains the path for original file and not the contents.
Removing soft link doesn’t affect anything but removing original file, the link becomes
“dangling” link which points to nonexistent file.
A soft link can link to a directory.
If we change the name of the original file then all the soft links for that file become
dangling i.e. they are worthless now.
Command to create a Soft link is:
$ ln -s [original filename] [link name]

File Permissions:

File ownership is an important component of UNIX that provides a secure method for
storing files.
Every file in Unix has the following attributes −
Owner permissions − The owner's permissions determine what actions the owner
of the file can perform on the file.
Group permissions − the group's permissions determine what actions a user, who
is a member of the group that a file belongs to, can perform on the file.
Other (world) permissions − The permissions for others indicate what action all
other users can perform on the file.
The permissions are broken into groups of threes, and each position in the group
denotes a specific permission, in this order: read (r), write (w), execute (x)
The first three characters (2-4) represent the permissions for the file's owner
The second group of three characters (5-7) consists of the permissions for the group to
which the file belongs.
The last group of three characters (8-10) represents the permissions for everyone else.

You might also like