Linux: Directory Structure


The author of this post is: Ahmed Bilal Jan (linkedin.com)

Linux file system or directory structure looks very strange to most of Linux users in their early days of encounter with Linux.

In this article I want to review some of key areas of Linux file system which may help new Linux users in getting familiar with it.

Please do not confuse file system with a format on how operating system stores files on hard disk, here by file system we mean how a Linux operating system organizes a data on individual computer.

Linux file system is derived from UNIX file system where it stores files in hierarchical tree. The top of this hierarchical tree structure is referred as root directory.

Linux consider everything as a file. Your hardware (HDD, Pen drives, CD ROM), boot media (Kernel, boot loader), configuration settings, user accounts etc from the eyes of Linux operating system all of them are files.

It’s a famous quote about Linux that “In Linux everything is file, if it’s not a file it’s a process”. So it’s very important for us to know how Linux directory structure is organized.

To get started use ls command, for example: ls / -l and you will be displayed with a folder which in turns contains many other directories like  bin, boot, cdrom, media, mnt, lib, var, root and many others.

What these folders contain? to answer we need to just go back and see what I wrote “Linux consider everything as a file”.

Your entire computer which Linux operating system sees is stored in these directories as files. Yes everything.

From binary executable of software you install on your hard disks to your configuration settings, from your boot media to user accounts, from operating system libraries to even your keyboard everything is file and is stored somewhere in a directory under “ / ”.

This “ / ” is refereed as root directory it has no parent directory everything else follow this directory.

It's very important for new comers to browse these directories under “ / ”  and then start understanding what each directory contains.

Just for illustration I am going to write one line description of important directories.

/bin: Binaries of command executed in shell reside here. Shell available for your distribution also reside here.

/boot: Files required for starting Linux resides here. Linux kernel, boot loader configuration files reside here.

/cdrom: Just for legacy support this directory is created to mount CD-ROM.

/dev: All hardware attached to your computer resides here in the form of files like HDD,keyboard,mouse.

/etc: Contains configuration files. This is one of most important directory.

/home: Contains home directories for users created on system.

/lib & /lib64: 32-bit and 64-bit libraries and kernel modules resides here respectively.

/media: External devices like HDD can be mounted here. Its just for legacy support.

/mnt: Also used as mounting point but specifically for temporarily mounted devices.

/opt: Software not managed by package manager reside here.

/proc: Contains runtime system information. It provides mechanism for kernel to send information to processes.

/run: Contains daemons which are required at very early stage of boot like systemd and udev.

/root: It’s the superuser/root user home directory.

/sbin: It's short of system binary. Contains binary files of important administrative commands.

/srv: Contains directories for services like HTTP/FTP.

/var: Contains variable data like log files, database files.

You should also know how to browse Linux directory structure via command line as GUI is not always available in Linux specially if you are working on Linux  server. There are few commands I would like to talk about.

$ pwd
: This command prints out your current directory. If you forget where you are, use this.

$ ls: This command is used to display contents of your current directory. Directory name are displayed in color form. Always use this to browse contents of directory.

$ tree: Display contents of directory in tree like form.

So question pops up in everyone mind. Does this Linux directory structure has any advantage? Yes it does. 


As you browse directories under root directory you may see that similar files are stored under same directory like logs files are under /var/log , binaries of commands executed in shell are stored in /bin,  library files are found under /lib and /lib64 and so on.

3 comentarios: