Understanding The Directory Structure In Linux
When a Linux operating system is installed, a specific directory structure is created by default, defining the hierarchy of files and directories in the system. Understanding this structure is vital for effectively managing and operating the system.
/ (Root)
├── bin
├── boot
├── dev
├── etc
├── home
│ ├── user1
│ └── user2
├── lib
├── media
├── mnt
├── opt
├── proc
├── root
├── run
├── sbin
├── srv
├── sys
├── tmp
├── usr
│ ├── bin
│ ├── include
│ ├── lib
│ ├── local
│ ├── sbin
│ └── share
└── var
├── cache
├── lib
├── local
├── lock
├── log
├── mail
├── opt
├── run
├── spool
└── tmp
Navigating To The Root Directory
In Linux, you can navigate to the root directory from any other directory by
using the cd
(change directory) command followed by a forward slash /
. Here
is the command:
cd /
The forward slash /
represents the root directory in a Unix-like operating
system like Linux. So, cd /
will change your present working directory to the
root directory. You can confirm this by using the pwd
(print working
directory) command, which should return /
.
Navigating to The Home Directory
In Unix-like operating systems, ~
is a shorthand or alias for the home
directory of the current logged-in user. So, when you use cd ~
, it changes the
current directory to the home directory of the user.
cd ~
For example, if you're logged in as a user named username
, running cd ~
would take you to the home directory of username
, usually located
at /home/username
in the filesystem. If you are the root user, cd ~
would
take you to /root
, which is the home directory for the root user.
Various Directories And Their Purpose
Let's delve into the key elements of the Linux directory structure and the significance of each default directory. These directories might vary based on the Linux distribution you are working on but most of them would be common across all Linux distros.
Directory | Description |
---|---|
/ | Root Directory: Every single file and directory starts from the root directory. It is the starting point of the file system hierarchy and holds other directories and subdirectories. Only root user has write privilege under this directory. |
/bin | Contains executable binary files, or commands that users typically run (e.g., ls, ping, grep, cp). Essential for both the system and the user. |
/sbin | Contains system binaries. Holds binary executables that only the root user or system administrator would need to use for system maintenance purposes (e.g., ifconfig, reboot, fdisk). |
/etc | Designated for system-wide configuration files. Holds important configuration files required by all system applications. Also includes start-up and shutdown shell scripts. |
/home | Personal space for users. Each user on the system will have a directory here, containing personal files, directories, and personal configuration files. |
/var | Contains variable data like system logging files, mail and printer spool directories, and transient and temporary files. Frequently utilized by various system programs/processes. |
/tmp | Holds temporary files used by system applications. Accessible to every user. Files in this directory are deleted every time the system restarts. |
/usr | Also known as Unix System Resources. Contains shareable, read-only data. Holds user binaries, libraries, documentation, and source code for second level programs. Similar to the /bin directory. |
/boot | Contains files needed to boot the system (e.g., GRUB boot loader's files, kernels, and other essential boot-up files). |
/lib | Contains kernel modules and shared library images required to boot the system and run the commands in the root file system. |
/dev | Contains device files. Linux treats everything like files, including devices. These files represent physical devices like hard drives and I/O devices. |
/proc | Contains information about system processes. This is a pseudo-filesystem containing information about running processes with a directory for each PID (Process Identification Number). |
/opt | For the installation of add-on software packages. Traditionally contains third-party software. |
/mnt | Mount point for temporarily mounted file systems. Administrators often mount other (temporary) file systems here. |
/media | Mount point for removable devices like USB sticks, CD-ROMs, or SD cards. |
/root | Home directory of the root user (superuser). Not the same as the root (/ ) directory. Usually located in the / directory and its actual location is /root . |
/srv | Contains data for services provided by the system. The naming and structuring within /srv is left to the discretion of the system administrator. |
Understanding these directories and their purposes can significantly enhance your competency in managing Linux systems, from performing basic operations to troubleshooting issues effectively.
Time To Transition From JavaScript To TypeScript
Level Up Your TypeScript And Object Oriented Programming Skills. The only complete TypeScript course on the marketplace you building TypeScript apps like a PRO.
SEE COURSE DETAILSWhat Can You Do Next 🙏😊
If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for ssoftware developers.