File System in Unix
File System in Unix
• /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.
• /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.
Mounting
• Mounting makes file systems, files, directories, devices and special
files available for use and available to the user.
• Its counterpart umount instructs the operating system that the file
system should be disassociated from its mount point, making it no
longer accessible and may be removed from the computer.
• /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.
• /sbin: Contains binary (executable) files, usually for system
administration. For example, fdisk and ifconfig utilities
• /kernel : Contains kernel files
• /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).
• /usr/bin : This directory stores all binary programs distributed with the operating
system not residing in /bin, /sbin or (rarely) /etc.
On UNIX systems there are two flavors of special files for each device,
• character special files and
• block special files :
• When a character special file is used for device Input/Output(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 Input/Output(I/O), data is
transferred in large fixed-size blocks. This type of access is called
block device access.
Pipes
• Pipes – UNIX allows you to link commands together using a pipe.
The pipe acts a temporary file which only exists to hold data from
one command until it is read by another.
• A Unix pipe provides a one-way flow of data. The output or result of
the first command sequence is used as the input to the second
command sequence.
• To make a pipe, put a vertical bar (|) on the command line between
two commands. For example: who | wc -l
• In long-format output of ls –l , named pipes are marked by the “p”
symbol.
File Attributes
File attributes
• file name: the name associated with the file (recall, this can be any type of file)
• modification date: the date the file was last modified, i.e. a "time-stamp". If
the file has not been modified within the last year (or six months for Linux),
the year of last modification is displayed.
• size: the size of the file in bytes (i.e. characters).2
• group: associated group for the file
• owner: the owner of the file
• number of links: the number of other links associated with this file
• permission modes: the permissions assigned to the file for the owner, the
group and all others.
Modifying File Permissions
inode
• An Inode number is a uniquely existing number for all the files in
Linux and all Unix type systems.
• When a file is created on a system, a file name and Inode number is
assigned to it.
• Generally, to access a file, a user uses the file name but internally file
name is first mapped with respective Inode number stored in a table.
• In Unix based operating system each file is indexed by an Inode. Inode
are special disk blocks they are created when the file system is
created. The number of Inode limits the total number of
files/directories that can be stored in the file system.
23
When are Inodes created?
• As we all now know that Inode is a data structure that contains
information of a file. Since data structures occupy storage then an
obvious question arises about when the Inodes are created in a
system? Well, space for Inodes is allocated when the operating
system or a new file system is installed and when it does its initial
structuring. So this way we can see that in a file system, maximum
number of Inodes and hence maximum number of files are set.
inode
• An inode is a data structure in UNIX operating systems that contains
important information pertaining to files within a file system. When a
file system is created in UNIX, a set amount of inodes is created, as
well. Usually, about 1 percent of the total file system disk space is
allocated to the inode table.
• The inode table contains a listing of all inode numbers for the
respective file system. When users search for or access a file, the
UNIX system searches through the inode table for the correct inode
number. When the inode number is found, the command in question
can access the inode and make the appropriate changes if applicable.
Example
• Take, for example, editing a file with vi. When you type vi <filename>,
the inode number is found in the inode table, allowing you to open
the inode. Some attributes are changed during the edit session of vi,
and when you have finished and typed :wq, the inode is closed and
released. This way, if two users were to try to edit the same file, the
inode would already have been assigned to another user ID (UID) in
the edit session, and the second editor would have to wait for the
inode to be released.
The following information is stored in inode:
• File type: regular file, directory, pipe etc.
• Permissions to that file: read, write, execute
• Link count: The number of hard link relative to an inode
• User ID: owner of file
• Group ID: group owner
• Size of file: or major/minor number in case of some special files
• Time stamp: access time, modification time and (inode) change time
• Attributes: immutable' for example
• Access control list: permissions for special users/groups
• Link to location of file
• Other metadata about the file
Inode Contents
• An Inode is a data structure containing metadata about the files.
• Following contents are stored in the Inode from a file:
• User ID of file
• Group ID of file
• Device ID
• File size
• Date of creation
• Permission
• Owner of the file
• File protection flag
• Link counter to determine number of hard links
ls -id new1 [To check inode contents]
Inode Table
• The Inode table contains all the Inodes and is created when file
system is created. The df -i command can be used to check how many
inodes are free and left unused in the filesystem.
• df -i
Inode Number
• Each Inode has a unique number and Inode number can be seen with
the help of ls -li command.
• Ls –li disk1
https://linoxide.com/linux-command/linux-inode/#:~:text=For%20example%2C%20the%20inode
%20contains,decided%20at%20filesystem%20creation%20time.