Linux File System Pdf

Linux File Systems for Windows doesn’t work in the kernel mode, but uses the Dokan library, which is similar to FUSE (Linux user mode file system), but for Windows OS. In short, Dokan enables to easily create a fully functional file system driver in a userspace program. For more information, please visit. The Linux File System. The Linux File System. Introduction All users of a Linux OS have an account name (also referred to as user namea or a login name) and a password. When your Linux account is created, you are also given a home directory where all of your files and folders will reside.

  • Unix / Linux for Beginners
  • Unix / Linux Shell Programming
  • Advanced Unix / Linux
  • Unix / Linux Useful Resources
  • Selected Reading

A file system is a logical collection of files on a partition or disk. A partition is a container for information and can span an entire hard drive if desired.

Your hard drive can have various partitions which usually contain only one file system, such as one file system housing the /file system or another containing the /home file system.

One file system per partition allows for the logical maintenance and management of differing file systems.

Everything in Unix is considered to be a file, including physical devices such as DVD-ROMs, USB devices, and floppy drives.

Directory Structure

Unix uses a hierarchical file system structure, much like an upside-down tree, with root (/) at the base of the file system and all other directories spreading from there.

A Unix filesystem is a collection of files and directories that has the following properties −

  • It has a root directory (/) that contains other files and directories.

  • Each file or directory is uniquely identified by its name, the directory in which it resides, and a unique identifier, typically called an inode.

  • By convention, the root directory has an inode number of 2 and the lost+found directory has an inode number of 3. Inode numbers 0 and 1 are not used. File inode numbers can be seen by specifying the -i option to ls command.

  • It is self-contained. There are no dependencies between one filesystem and another.

The directories have specific purposes and generally hold the same types of information for easily locating files. Following are the directories that exist on the major versions of Unix −

Sr.No.Directory & Description
1

/

This is the root directory which should contain only the directories needed at the top level of the file structure

2

/bin

This is where the executable files are located. These files are available to all users

3

/dev

These are device drivers

4

/etc

Supervisor directory commands, configuration files, disk configuration files, valid user lists, groups, ethernet, hosts, where to send critical messages

5

/lib

Contains shared library files and sometimes other kernel-related files

6

/boot

Contains files for booting the system

7

/home

Contains the home directory for users and other accounts

8

/mnt

Used to mount other temporary file systems, such as cdrom and floppy for the CD-ROM drive and floppy diskette drive, respectively

9

/proc

Contains all processes marked as a file by process number or other information that is dynamic to the system

10

/tmp

Holds temporary files used between system boots

11

/usr

Used for miscellaneous purposes, and can be used by many users. Includes administrative commands, shared files, library files, and others

12

/var

Typically contains variable-length files such as log and print files and any other type of file that may contain a variable amount of data

13

/sbin

Contains binary (executable) files, usually for system administration. For example, fdisk and ifconfig utlities

14

/kernel

Contains kernel files

Navigating the File System

Now that you understand the basics of the file system, you can begin navigating to the files you need. The following commands are used to navigate the system −

Sr.No.Command & Description
1

cat filename

Displays a filename

2

cd dirname

Moves you to the identified directory

3

cp file1 file2

Copies one file/directory to the specified location

4

file filename

Identifies the file type (binary, text, etc)

5

find filename dir

Finds a file/directory

6

head filename

Shows the beginning of a file

7

less filename

Browses through a file from the end or the beginning

8

ls dirname

Shows the contents of the directory specified

9

mkdir dirname

Creates the specified directory

10

more filename

Browses through a file from the beginning to the end

11

mv file1 file2

Moves the location of, or renames a file/directory

12

pwd

Shows the current directory the user is in

13

rm filename

Removes a file

14

rmdir dirname

Removes a directory

15

tail filename

Shows the end of a file

16

touch filename

Creates a blank file or modifies an existing file or its attributes

17

whereis filename

Shows the location of a file

18

which filename

Shows the location of a file if it is in your PATH

You can use Manpage Help to check complete syntax for each command mentioned here.

The df Command

The first way to manage your partition space is with the df (disk free) command. The command df -k (disk free) displays the disk space usage in kilobytes, as shown below −

Some of the directories, such as /devices, shows 0 in the kbytes, used, and avail columns as well as 0% for capacity. These are special (or virtual) file systems, and although they reside on the disk under /, by themselves they do not consume disk space.

The df -k output is generally the same on all Unix systems. Here's what it usually includes −

Sr.No.Column & Description
1

Filesystem

The physical file system name

2

kbytes

Total kilobytes of space available on the storage medium

3

used

Total kilobytes of space used (by files)

4

avail

Total kilobytes available for use

5

capacity

Percentage of total space used by files

6

Mounted on

What the file system is mounted on

You can use the -h (human readable) option to display the output in a format that shows the size in easier-to-understand notation.

The du Command

The du (disk usage) command enables you to specify directories to show disk space usage on a particular directory.

This command is helpful if you want to determine how much space a particular directory is taking. The following command displays number of blocks consumed by each directory. A single block may take either 512 Bytes or 1 Kilo Byte depending on your system.

The -h option makes the output easier to comprehend −

Mounting the File System

A file system must be mounted in order to be usable by the system. To see what is currently mounted (available for use) on your system, use the following command −

The /mnt directory, by the Unix convention, is where temporary mounts (such as CDROM drives, remote network drives, and floppy drives) are located. If you need to mount a file system, you can use the mount command with the following syntax −

For example, if you want to mount a CD-ROM to the directory /mnt/cdrom, you can type −

This assumes that your CD-ROM device is called /dev/cdrom and that you want to mount it to /mnt/cdrom. Refer to the mount man page for more specific information or type mount -h at the command line for help information.

After mounting, you can use the cd command to navigate the newly available file system through the mount point you just made.

Unmounting the File System

To unmount (remove) the file system from your system, use the umount command by identifying the mount point or device.

For example, to unmount cdrom, use the following command −

The mount command enables you to access your file systems, but on most modern Unix systems, the automount function makes this process invisible to the user and requires no intervention.

User and Group 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 −

Linux
Sr.No.Command & Description
1

quota

Displays disk usage and limits for a user of group

2

edquota

This is a quota editor. Users or Groups quota can be edited using this command

3

quotacheck

Scans a filesystem for disk usage, creates, checks 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 enabled on one or more filesystems

6

quotaoff

This announces to the system that disk quotas should be disabled for one or more filesystems

7

repquota

This prints a summary of the disc usage and quotas for the specified file systems

You can use Manpage Help to check complete syntax for each command mentioned here.

If you’re coming from Windows, the Linux file system structure can seem particularly alien. The C: drive and drive letters are gone, replaced by a / and cryptic-sounding directories, most of which have three letter names.

The Filesystem Hierarchy Standard (FHS) defines the structure of file systems on Linux and other UNIX-like operating systems. However, Linux file systems also contain some directories that aren’t yet defined by the standard.

System

/ – The Root Directory

Everything on your Linux system is located under the / directory, known as the root directory. You can think of the / directory as being similar to the C: directory on Windows – but this isn’t strictly true, as Linux doesn’t have drive letters. While another partition would be located at D: on Windows, this other partition would appear in another folder under / on Linux.

/bin – Essential User Binaries

The /bin directory contains the essential user binaries (programs) that must be present when the system is mounted in single-user mode. Applications such as Firefox are stored in /usr/bin, while important system programs and utilities such as the bash shell are located in /bin. The /usr directory may be stored on another partition – placing these files in the /bin directory ensures the system will have these important utilities even if no other file systems are mounted. The /sbin directory is similar – it contains essential system administration binaries.

File

/boot – Static Boot Files

The /boot directory contains the files needed to boot the system – for example, the GRUB boot loader’s files and your Linux kernels are stored here. The boot loader’s configuration files aren’t located here, though – they’re in /etc with the other configuration files.

/cdrom – Historical Mount Point for CD-ROMs

The /cdrom directory isn’t part of the FHS standard, but you’ll still find it on Ubuntu and other operating systems. It’s a temporary location for CD-ROMs inserted in the system. However, the standard location for temporary media is inside the /media directory.

/dev – Device Files

Linux exposes devices as files, and the /dev directory contains a number of special files that represent devices. These are not actual files as we know them, but they appear as files – for example, /dev/sda represents the first SATA drive in the system. If you wanted to partition it, you could start a partition editor and tell it to edit /dev/sda.

This directory also contains pseudo-devices, which are virtual devices that don’t actually correspond to hardware. For example, /dev/random produces random numbers. /dev/null is a special device that produces no output and automatically discards all input – when you pipe the output of a command to /dev/null, you discard it.

/etc – Configuration Files

The /etc directory contains configuration files, which can generally be edited by hand in a text editor. Note that the /etc/ directory contains system-wide configuration files – user-specific configuration files are located in each user’s home directory.

/home – Home Folders

The /home directory contains a home folder for each user. For example, if your user name is bob, you have a home folder located at /home/bob. This home folder contains the user’s data files and user-specific configuration files. Each user only has write access to their own home folder and must obtain elevated permissions (become the root user) to modify other files on the system.

/lib – Essential Shared Libraries

The /lib directory contains libraries needed by the essential binaries in the /bin and /sbin folder. Libraries needed by the binaries in the /usr/bin folder are located in /usr/lib.

/lost+found – Recovered Files

Each Linux file system has a lost+found directory. If the file system crashes, a file system check will be performed at next boot. Any corrupted files found will be placed in the lost+found directory, so you can attempt to recover as much data as possible.

/media – Removable Media

The /media directory contains subdirectories where removable media devices inserted into the computer are mounted. For example, when you insert a CD into your Linux system, a directory will automatically be created inside the /media directory. You can access the contents of the CD inside this directory.

/mnt – Temporary Mount Points

Historically speaking, the /mnt directory is where system administrators mounted temporary file systems while using them. For example, if you’re mounting a Windows partition to perform some file recovery operations, you might mount it at /mnt/windows. However, you can mount other file systems anywhere on the system.

/opt – Optional Packages

The /opt directory contains subdirectories for optional software packages. It’s commonly used by proprietary software that doesn’t obey the standard file system hierarchy – for example, a proprietary program might dump its files in /opt/application when you install it.

/proc – Kernel & Process Files

Linux Kernel Virtual File System Pdf

The /proc directory similar to the /dev directory because it doesn’t contain standard files. It contains special files that represent system and process information.

/root – Root Home Directory

The /root directory is the home directory of the root user. Instead of being located at /home/root, it’s located at /root. This is distinct from /, which is the system root directory.

/run – Application State Files

The /run directory is fairly new, and gives applications a standard place to store transient files they require like sockets and process IDs. These files can’t be stored in /tmp because files in /tmp may be deleted.

/sbin – System Administration Binaries

The /sbin directory is similar to the /bin directory. It contains essential binaries that are generally intended to be run by the root user for system administration.

/selinux – SELinux Virtual File System

If your Linux distribution uses SELinux for security (Fedora and Red Hat, for example), the /selinux directory contains special files used by SELinux. It’s similar to /proc. Ubuntu doesn’t use SELinux, so the presence of this folder on Ubuntu appears to be a bug.

/srv – Service Data

Linux File System Check

The /srv directory contains “data for services provided by the system.” If you were using the Apache HTTP server to serve a website, you’d likely store your website’s files in a directory inside the /srv directory.

/tmp – Temporary Files

Applications store temporary files in the /tmp directory. These files are generally deleted whenever your system is restarted and may be deleted at any time by utilities such as tmpwatch.

/usr – User Binaries & Read-Only Data

The /usr directory contains applications and files used by users, as opposed to applications and files used by the system. For example, non-essential applications are located inside the /usr/bin directory instead of the /bin directory and non-essential system administration binaries are located in the /usr/sbin directory instead of the /sbin directory. Libraries for each are located inside the /usr/lib directory. The /usr directory also contains other directories – for example, architecture-independent files like graphics are located in /usr/share.

The /usr/local directory is where locally compiled applications install to by default – this prevents them from mucking up the rest of the system.

/var – Variable Data Files

The /var directory is the writable counterpart to the /usr directory, which must be read-only in normal operation. Log files and everything else that would normally be written to /usr during normal operation are written to the /var directory. For example, you’ll find log files in /var/log.

For more detailed technical information about the Linux file system hierarchy, consult the Filesystem Hierarchy Standard documentation.

READ NEXT
  • › What Is Patch Tuesday for Windows, and When Is It?
  • › How to Disable Interactive Pop-Up Ads on Your Roku TV
  • › What’s New in macOS 10.15 Catalina, Available Now
  • › How to Copy and Back Up Files To External Storage on iPhone and iPad
  • › Everything You Need to Know About Co-Authoring in Excel