What is the Linux File System? Unix / Linux File System Basics explained

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. If you are new to the Linux operating system, then you might not be familiar with the file system. You need to cover this topic if you want to grow as a Linux user.

What is the Linux file system?

Linux File System or any file system generally is a layer which is under the operating system that handles the positioning of your data on the storage, without it; the system cannot knows which file starts from where and ends where. Even if you find any unsupported file system type

A Linux File System is a logical bundle of files on the disk or partition. Partition is a container that stores information and can even span a whole hard drive if it is required. A hard drive can be consist of various partitions which generally consist of only one file system such a file system housing /file system and another naming /home file system.

In one partition, a single file system is allowed for the logical maintenance and management of the different file system. In Unix, everything is considered to be a file, even the physical devices like DVD ROMs, USB, and floppy drives are considered as the file.

The Directory Structure

In Unix, a hierarchical File System structure is used like an upside-down tree which has a root at the base of the file system and all other directories are spread around like the branches. The Unix files and directories have the following properties –

  • It contains root / which is consists of other files and directories.
  • Every single file and directory is named uniquely for easy identification, the directory in which file is located is mainly known as an inode.
  • By default, the root directory has an inode number of 2 and the lost and found directory has an inode number of 3. File Inode numbers can be seen by specifying the -1 option to Is command.
  • They are self-sufficient, there are no dependencies between two file systems required.

Every directory has a specific purpose and holds the same types of information for the quick file allocation. Below the list of the major Linux directories and their roles have been elaborated.

Linux directory

  • /“ – It is the root directory that contains only the directories needed at the top level of the file system.
  • /bin” – This is the directory where all the executable files are situated. These files are available for every user.
  • /dev” – These directories are related to the device drivers.
  • /etc” – It is a superior directory command like configuration files, disk configuration files, valid user lists, groups, ethernet, hosts, where to send critical messages.
  • /boot” – All the booting files are stored in this directory.
  • “/home” – It is a place where a home directory for users and other accounts are available.
  • /mnt” – It is used to mount other temporary files like CD-ROM and floppy.
  • /proc” – Here, all the processes marked as a file by process number in the system are kept.
  • /tmp” – The temporary files used between the system are held here.
  • /usr” – It can be used by the user for miscellaneous purposes including administrative commands, shared files, library files, and others.
  • /var” – This mainly contains the variable-length file like log and print files or any other type of the file that may contain a variable amount of the data.
  • /sbin” – This a place for binary execution files for system administrator like fdisk and ifconfig utilities.
  • /kernel” – It is consist of kernel files.

Navigating the File System

Now, as we have studied the basics of the file system, then the next step is to navigate the files you need from the system. The basic navigation commands that you can use are –

  • Cat filename – This command is used to display the file name.
  • cd dirname – It is used to move the identified directory.
  • cp file 1 file 2 – It is useful to copy one file and directory to a specific location.
  • filename – This line of command is used to identify the file type.
  • find filename dir – It is used to find the file or directory.
  • head filename – It shows the beginning of the file name.
  • less filename Browses through a file from the end or the beginning
  • ls dirname – Shows the contents of the directory specified
  • mkdir dirname – Creates the specified directory
  • more filename – Browses through a file from the beginning to the end
  • mv file1 file2 – Moves the location of, or renames a file/directory
  • pwd – Shows the current directory the user is in
  • rm filename – Removes a file
  • rmdir dirname – Removes a directory
  • tail filename – Shows the end of a file
  • touch filename – Creates a blank file or modifies an existing file or its attributes
  • whereis filename – Shows the location of a file
  • which filename – Shows the location of a file if it is in your PATH

There are plenty of other navigation commands available. To know more about other commands and their syntax you can use the Manage Help option.

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 −

$df -k

Filesystem      1K-blocks      Used   Available Use% Mounted on

/dev/vzfs        10485760   7836644     2649116  75% /

/devices                0         0           0   0% /devices

$

Filesystem – The physical file system name
kbytes – Total kilobytes of space available on the storage medium
used – Total kilobytes of space used (by files)
avail – Total kilobytes available for use
capacity – Percentage of total space used by files
Mounted on – What the file system is mounted on

Some directories like /dev only show 0 in the kbytes and almost avail 0% capacity. These are special file systems, they don’t reside on the disk under root and they don’t consume any space over the disk.

The du Command

It is a disk usage command that helps you in specify directories to show the disk usage space on the particular directory. It is a useful command when you want to determine the space taken by particular directory on the disk. In below-mentioned command, several blocks used by each directory have been calculated.

$du /etc

10     /etc/cron.d

126    /etc/default

6      /etc/dfs

$

The -h option makes the output easier to comprehend −

$du -h /etc

5k    /etc/cron.d

63k   /etc/default

3k    /etc/dfs

$

Linux File System is a very deep concept and can’t be fully expressed in one small post. In file system guide, there is multiple other layers remain undiscussed like mounting, unmounting and much more. But, the basics of the file system are discussed in the post which is sufficient to start with the Linux operating system.

Also read:

Leave a Reply

Your email address will not be published.