Posted in: Linux, Unix

File system hierarchy in Linux

In Unix/Linux everything is organized in the form of files, whether it’s devices, directories, files, etc. A file is a smallest unit in which the information is stored.


Directories and their usage –

/The file system root.
/root  The home directory of the root user. The root user’s home directory is located outside of /home in order to make sure the root user may log in even without /home being available and mounted.
/sbinLike /bin,  this  directory  holds commands needed to boot the system, but which are usually not executed by normal users.
/bootThis contains files needed to start up the system, including the Linux kernel, a RAM disk image and bootloader configuration files.
/devThis directory has all device files.
/etcIt contains system-specific configuration files.
/homeThe location contains users’ home directories.
/libContains very important dynamic libraries and kernel modules.
/mntThis directory shows the manually or temporarily mounted filesystems
/opt  location for any other 3rd party software for the system  
/proc  A virtual kernel file system exposing the process list and other functionality.  
/binThis has the binary files for all the commands, like cat,cp,zip,etc. This directory contains executable programs which are needed in single user mode and to bring the system up or repair it.
/run  It is a tmpfs (temporary file system) for system packages to place runtime data in.  
/run/log  Location for run-time system logs  
/sbin  contains important administrative commands that should generally only be employed by the superuser.  
/sys  sys is a virtual filesystem that can be accessed to set or obtain information about the kernel’s view of the system.  
/tmp  This is location for temporary files used by applications.  
/usr  Contains user utilities and applications, and partly replicates the root directory structure, containing for instance, among others, /usr/bin/ and /usr/lib.  
/var  This is for variable data, i.e. data which is likely to be changed. Example logs, spool, crash, cache files.  

fstab –

The file /etc/fstab is a file with table containing descriptive information about the filesystems the system can mount.

The file /etc/fstab is a file with table containing descriptive information about the filesystems the system can mount.
# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>  <type>  <options>      <dump>  <pass>
# / was on /dev/sda3 during installation
UUID=9276c0f9-8692-424a-8a81-4ed0c8d4e00a /              ext4    errors=remount-ro 0      1
# /boot/efi was on /dev/sda2 during installation
UUID=C18D-C5BB  /boot/efi      vfat    umask=0077      0      1
/swapfile                                none            swap    sw              0      0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0      0

Command to check the free space on each of the file system –
# df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs          390M  2.1M  388M  1% /run
/dev/sda3        23G  11G  12G  49% /
tmpfs          2.0G    0  2.0G  0% /dev/shm
tmpfs          5.0M  4.0K  5.0M  1% /run/lock
tmpfs          2.0G    0  2.0G  0% /run/qemu
/dev/sda2      512M  5.3M  507M  2% /boot/efi
tmpfs          390M  4.7M  385M  2% /run/user/1000

You can check the large files using du or find command.

du (disk usage) can be used to find the largest files in specified path. With find command, we can look for files larger than specified size.

# du -a /var | sort -n -r | head -n 5
3253608 /var
2633596 /var/lib
2088656 /var/lib/snapd
1434112 /var/lib/snapd/snaps
652708 /var/lib/snapd/seed


# find / -type f -size +1G -print | xargs ls -lh
-rw-rw-r-- 1 jay jay 64G Jun 28 10:16 /home/jay/.docker/desktop/vms/0/data/Docker.raw
-r-------- 1 root root 128T Jul 1 11:49 /proc/kcore
-rw------- 1 root root 1.1G Jun 28 09:30 /swapfile
Here we can use "G" or "M" for GB or MB respectively.
Back to Top