Have you ever seen common directories like /etc, /var or /usr while exploring your Linux terminal? Or maybe you were searching something up on an online forum but you don’t know anything about them? Or maybe you don’t know what these directories are for or what’s the ideal files to store in them? Well that’s the topic of today where we will be discussing common directories found in Linux.
Each /[name] represents a directory and its name. A directory is simply a folder containing files or subdirectories (directories cascaded). A system makes use of directories to simply store data within them in the form of files and efficiently retrieve these files once that data is called by an action. These actions can be processes created by programs, commands or by the operating system requesting certain files with a certain path.
To better visualise a directory, simply picture this. You keep all your pens in your top right hand side drawer in your study table. Whenever you need to write something, you know that the pens can be found on the top right hand side drawer. So you easily know where to look, when you need a pen. Directories operate somewhat the same way, where an action requests the data and the system retrieves that data from a specific directory. We won’t elaborate further on how the operating system tries to look for the data especially for new directories, as this goes out of the scope of this article. This will be explained however in a future article.
Now that we understand what directories are used for, we can dive deeper on the most common directories found in a Linux system. All Linux distributions (Ubuntu, Debian, Redhat) follow the same tree directory structure.
All directories share the same parent directory called the root (“/”). On Windows we have volumes for each drive and a unique letter such as C:\ or E:\ but on Linux we have the root directory which serves as a base for all directories.
/home – Logging onto your Linux machine you find yourself in the home directory. New user accounts by default have their home directory under /home where individual users store their date within their profile. Also the same way how in Windows we have the Desktop folder or the Download folder, Linux users have the same structure within /home.
zigbii@NetworkZig:~$ pwd
/home/zigbii
zigbii@NetworkZig:~$ ls -la
total 84
drwxr-xr-x 2 zigbii zigbii 4096 May 18 20:49 Desktop
drwxr-xr-x 2 zigbii zigbii 4096 May 18 20:49 Documents
drwxr-xr-x 2 zigbii zigbii 4096 May 18 20:49 Downloads
drwxr-xr-x 2 zigbii zigbii 4096 May 18 20:49 Music
drwxr-xr-x 2 zigbii zigbii 4096 May 18 20:49 Pictures
drwxr-xr-x 2 zigbii zigbii 4096 May 18 20:49 Public
drwx------ 4 zigbii zigbii 4096 May 18 21:00 snap
drwxr-xr-x 2 zigbii zigbii 4096 May 18 20:49 Videos
/bin – This directory contains binary or executable programs. Those familiar with basic linux commands such as “ls” (which list all files within that directory) or “cat” (which prints all content within a file to be viewed on the terminal) have these commands stored in /bin. Each time we run the ls command in the terminal, there is an environment variable that searches within the bin directory and runs its binary file.
zigbii@NetworkZig:~$ ls -la /bin
lrwxrwxrwx 1 root root 7 Apr 22 15:08 /bin -> usr/bin
zigbii@zigbii-NetworkZig:~$ ls -la /usr/bin | grep ls
-rwxr-xr-x 1 root root 142312 Apr 5 16:36 ls
/etc – This directory contains system configuration files. One file in particular that is very common by system administrators is the hosts file. This hosts file contains lines of strings to IP addresses. For instance, I would like to check that the local news website is online, so I try to ping bbc. The ping command on my local machine doesn’t request the DNS and so it doesn’t know what IP the bbc website has. So I can create an entry binding with the website static IP so each time I need to ping bbc it looks up the IP within the hosts file.
127.0.0.1 localhost
127.0.1.1 NetworkZig
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
151.101.128.81 bbc
zigbii@NetworkZig:~$ ping bbc
PING bbc (151.101.128.81) 56(84) bytes of data.
64 bytes from bbc (151.101.128.81): icmp_seq=1 ttl=53 time=32.0 ms
64 bytes from bbc (151.101.128.81): icmp_seq=2 ttl=53 time=32.3 ms
64 bytes from bbc (151.101.128.81): icmp_seq=3 ttl=53 time=31.3 ms
^C
--- bbc ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 31.256/31.854/32.319/0.444 ms
/var – The var directory has saved the jobs of countless IT professionals. When troubleshooting an issue for a service or an incompatible driver, the first thing we check in this directory are important log files such as /var/log/dmesg which display kernel messages or /var/log/journal which contain logs related to services.
/usr – Files or programs related to system wide users are stored here. More specifically and well known, are locale (keyboard layouts or languages) and man pages which are quite popular amongst Linux users.
zigbii@NetworkZig:~$ ls -la /usr/bin/man
-rwxr-xr-x 1 root root 128416 Apr 8 16:45 /usr/bin/man
*Note – The man command is short for manual in Linux. This is a good way for users to search the man pages for details related to particular commands. The following is the first part of the man pages related to the ls command.
zigbii@NetworkZig:~$ man ls
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default). Sort entries
alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
--author
with -l, print the author of each file
-b, --escape
print C-style escapes for nongraphic characters
--block-size=SIZE
with -l, scale sizes by SIZE when printing them; e.g., '--block-size=M';
see SIZE format below
-B, --ignore-backups
do not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last change of file status in‐
formation); with -l: show ctime and sort by name; otherwise: sort by ctime,
newest first
-C list entries by columns
--color[=WHEN]
color the output WHEN; more info below
/tmp – Temporary or junk files created by programs reside here. The tmp directory is somewhat vital as after a system reboot all files within this directory are cleared, preserving system storage. This part of storage is volatile and users are not recommended to save files in the tmp directory unless experimenting within a script and storing their output files in the /tmp. However this directory might be unfruitful in a server environment where the system uptime is always on.
/opt – Installations of third-party programs or optional programs typically reside within this directory. However, for each program, always check the documentation. Shared scripts among users can be stored under /opt or /usr.
*Note – You can view the entire Linux directory system with the tree command.
Conclusion
Administering a linux system proves easier when understanding the Linux directory structure. In today’s article we discussed the purpose of the root directory which is the highest level structure and is used as a base for each directory. Under the root directory there is /home, /bin, /etc, /var, /usr, /tmp, /opt to name a few common directories. The home directory is used as the location for linux user data profiles. Bin contains binary and executable programs. System configuration files reside in /etc and var is mostly known for logs. Usr have relevant files shared to all system wide users. Tmp files are volatile and anything stored within this directory is lost after a reboot or shutdown. Opt contains files data related to third-party programs.
Leave a Reply