Directory/Filesystem structure in Linux

Share this article

In the What is File System in Linux article we understood what is Linux file system. The main highlights are following:

  • It is formed of directories and files.
  • File system also contains their metadata to control the data storage.
  • Metadata is basically name of the file or folder, where it is stored , time of creation, permissions assigned to it etc.

This article will explain important directories in Linux and how it organizes the structure of files in Linux .

/ : root

  • In Linux, most of the files system can be distinguished as a hierarchical filesystem, where root directory or simply root is the top on the hierarchy or the root of a filesystem.
  • The root directory is just forward slash ( / ).
  • You can use the following command to reach the directory but you have to be a root user to access the root folder.
[centos@test ~]$ sudo su 
[root@test centos]# cd /
[root@test /]# 
  • As the root is top of the hierarchy, it contains all the files and folders. Incoming sections, we will see important files and directories for system organization in the root directory
  • Below output of the tree command, shows the files and folder of the root directory.
root@ubuntu-exp:/# tree / -L 1
/
├── bin -> usr/bin
├── boot
├── dev
├── etc
├── home
├── lib -> usr/lib
├── lib32 -> usr/lib32
├── lib64 -> usr/lib64
├── libx32 -> usr/libx32
├── lost+found
├── media
├── mnt
├── opt
├── proc
├── root
├── run
├── sbin -> usr/sbin
├── snap
├── srv
├── sys
├── tmp
├── usr
└── var

Next section we will discuss all the directory which is seen in the above output. These directories have important significance in the Linux

/root : Home for root user

  • /root directory is root user home directory don’t confuse it with /, both are two different directories.

/bin -> usr/bin : User Binaries

  • -> sign show the symbolic link to /usr/bin directory. You can think it as a shortcut in window.
  • This folder contains binary executables ( commands), the content of these file you can not read.
  • Executables which are in this directory can be executed by all the system users. Examples are apt, ls, grep etc.

There are hundreds of files in /bin folder, therefore, listing only apt-file.

root@ubuntu-exp:/# ls bin/apt
bin/apt
root@ubuntu-exp:/#

/boot : Boot directory.

  • This is the most sacred place/directory in our file system. You don’t wanna mess here.
  • This directory contains bootloader and the linux kernel.

The following tree command shows the content of the boot folder.

root@ubuntu-exp:~# tree /boot -L 2
/boot
├── System.map-5.4.0-45-generic
├── System.map-5.4.0-80-generic
├── System.map-5.4.0-81-generic
├── config-5.4.0-45-generic
├── config-5.4.0-80-generic
├── config-5.4.0-81-generic
├── efi
│   ├── EFI
│   └── boot
├── grub
│   ├── fonts
│   ├── gfxblacklist.txt
│   ├── grub.cfg
│   ├── grubenv
│   ├── i386-pc
│   ├── unicode.pf2
│   └── x86_64-efi
├── initrd.img -> initrd.img-5.4.0-81-generic
├── initrd.img-5.4.0-45-generic
├── initrd.img-5.4.0-80-generic
├── initrd.img-5.4.0-81-generic
├── initrd.img.old -> initrd.img-5.4.0-80-generic
├── vmlinuz -> vmlinuz-5.4.0-81-generic
├── vmlinuz-5.4.0-45-generic
├── vmlinuz-5.4.0-80-generic
├── vmlinuz-5.4.0-81-generic
└── vmlinuz.old -> vmlinuz-5.4.0-80-generic

7 directories, 20 files
root@ubuntu-exp:~#

/dev : Device directory

  • This directory contains device files which are attached to the system

The below example shows the storage device attached to the systems

[centos@test ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 10G 0 disk
└─sda1 8:1 0 10G 0 part /
sdb 8:16 0 10G 0 disk
sdc 8:32 0 5G 0 disk
└─sdc1 8:33 0 5G 0 part
├─vg--test-data01 253:0 0 2G 0 lvm /var/data02
└─vg--test-data02 253:1 0 8G 0 lvm /var/data02
sdd 8:48 0 5G 0 disk
└─sdd1 8:49 0 5G 0 part
└─vg--test-data02 253:1 0 8G 0 lvm /var/data02
[centos@test ~]$

You can see all the devices’ files in /dev/ directory. See below-mentioned output

[centos@test ~]$ ls /dev/sd*
/dev/sda /dev/sda1 /dev/sdb /dev/sdc /dev/sdc1 /dev/sdd /dev/sdd1
[centos@test ~]$

/etc : Everything to configure directory

  • This directory is the most intersting directory which is the dumping ground of all the programs configuration files.
  • Comes handy to configure the programs according to our need. Some important files as examples: /etc/resolv.conf, /etc/logrotate.conf, /etc/ssh/sshd.conf.

/home : Home Directories

  • This direcotries contains home directories for all users in the system.
  • These directories contains personal data of all the user.

See the example below, As we have two users kolla and ubuntu. It shows their home directory with the user name.

root@ubuntu-exp:/usr# tree /home -L 2
/home
├── kolla
└── ubuntu
      └── wallaby

3 directories, 0 files
root@ubuntu-exp:/usr#

/lib : System Libraries

  • Library files contain functions which are used by the binaries located under /bin and /sbin
  • Library filenames are generally start with ls*, ld* or end with lib.so but not always.

/media : Removable Devices

  • This is also temporary mount directory
  • This is basically used for removable devices like USB drives, for CD-ROM etc.

/mnt : Mount Directory

  • This basically temprory mount directory.
  • System admin usually use this to mount filesystems.

/opt: optional

  • holds option packages.
  • Used by the system administrator when installing software locally. There is no hard and fast rule when to install or what packacage to install in /opt directory

/proc : Process Information

  • We know that when program is running it is called process
  • This directory contains files or folders which gives the information about the process.
  • When you explore the directory structure it would look like /proc/{some_number}.

Below snapshot is an example, where I am showing that you will have a subdirectory in your /proc directory with the PID number.

/sbin : System binaries

  • Similarly like previous folder bin stands for Binaries and s stands for system which means system binaries
  • Again /sbin also contains binary executables.
  • /sbin files are not executable by simple user, these files or command can be run by the system administrator

Some content of the /sbin folder.

root@ubuntu-exp:/# tree /sbin/ -L 1
/sbin/
├── aa-remove-unknown
├── aa-status
├── aa-teardown
├── accessdb
├── add-shell
├── addgnupghome
├── addgroup -> adduser
├── adduser

/srv : Service Data

  • Contains site specific services data.
  • Again there is no specific way to store data here you can think structuring data by protocols eg. ftp, www, cvs etc
One method for
  structuring data under /srv is by protocol, eg. ftp, rsync, www, and cvs.
  • For example, /srv/cvs contains CVS related data.

/tmp : Temporary directory

  • This is for short term storage when system is rebooted the files and directory stored in this folder is deleted.

/usr : User Programs

  • Content of the /usr directory shown in the following code section
root@ubuntu-exp:/usr# tree -L 1
.
├── bin
├── games
├── include
├── lib
├── lib32
├── lib64
├── libexec
├── libx32
├── local
├── sbin
├── share
└── src

12 directories, 0 files
root@ubuntu-exp:/usr#
  • Contains binaries, libraries, documentation, and source-code for second level programs.
  • In other section we have already discussed some of the subdirectories like bin, lib, and lib32 etc

/var : Variable

  • The var directory stores variable files.
  • Variable files mean the content of the files are varying means increasing or decreasing.
    As an example see the /var/log/ directory where the logs are being written. In this directory file size keep increasing when it reach to certain limit then file is compressed with other similar old logs for future refrence. Even in future these compressed logs are cleaned up by system.
root@ubuntu-exp:~# tree /var/log
/var/log
├── alternatives.log
├── apt
│   ├── eipp.log.xz
│   ├── history.log
│   └── term.log
├── auth.log
├── auth.log.1
├── auth.log.2.gz
├── auth.log.3.gz
├── auth.log.4.gz
├── btmp
├── cloud-init-output.log
├── cloud-init.log
├── dist-upgrade
├── dmesg
├── dpkg.log
├── journal
│   └── 9a6cbdf44fb64b2e9fe919d08c0a0336
│   ├── system.journal
│   ├── system@79a1aac15b714c4cb0f96e927d1e6c6b-0000000000000001-0005c8a475650089.journal
│   ├── system@79a1aac15b714c4cb0f96e927d1e6c6b-00000000000011ae-0005c8ad045c2f76.journal
│   ├── system@79a1aac15b714c4cb0f96e927d1e6c6b-0000000000003dcb-0005c8cc1304b827.journal
│   ├── system@79a1aac15b714c4cb0f96e927d1e6c6b-0000000000010529-0005c96da7443f23.journal
│   ├── system@79a1aac15b714c4cb0f96e927d1e6c6b-000000000001bb06-0005ca02969b941e.journal
│   ├── user-1000.journal
│   ├── user-1000@d98884eaddd44cc58b1cae0070b2bf5b-00000000000004c9-0005c8a4befa03d2.journal
│   ├── user-1000@d98884eaddd44cc58b1cae0070b2bf5b-00000000000011cb-0005c8ad048e1962.journal
│   ├── user-1000@d98884eaddd44cc58b1cae0070b2bf5b-0000000000003ddb-0005c8cc13211ad5.journal
│   ├── user-1000@d98884eaddd44cc58b1cae0070b2bf5b-0000000000018659-0005c9d982f98abe.journal
│   ├── user-1000@d98884eaddd44cc58b1cae0070b2bf5b-000000000001e38d-0005ca228837ea68.journal
│   ├── user-42401.journal
│   ├── user-42401@0be2e94b8cca493da2af342ff8154927-000000000000128b-0005c8ad10fe39eb.journal
│   ├── user-42401@0be2e94b8cca493da2af342ff8154927-0000000000003e82-0005c8cc14bfd711.journal
│   ├── user-42439.journal
│   └── user-42439@375173868cc647f684862cfd6240874f-0000000000004d49-0005c8ce9f7c0a41.journal
├── kern.log
├── kern.log.1
├── kern.log.2.gz
├── kolla -> /var/lib/docker/volumes/kolla_logs/_data
├── landscape
│   └── sysinfo.log
├── lastlog
├── private
├── syslog
├── syslog.1
├── syslog.2.gz
├── unattended-upgrades
│   ├── unattended-upgrades-dpkg.log
│   ├── unattended-upgrades-shutdown.log
│   └── unattended-upgrades.log
└── wtmp

8 directories, 45 files
root@ubuntu-exp:~#

Leave a Comment

Your email address will not be published. Required fields are marked *