You navigate through linux file system using cd
command which means "change directory". You can use ls
command to print the files and sub-directories of any directory or use ll
command to check their permission and modified time as well.
The root directory in the Linux file system is denoted by a single forward slash (/
). It is the top-most directory in the hierarchy of the file system and acts as the starting point for all other directories and files. Everything on a Linux system, including all mounted filesystems, starts from the root directory.
The root directory typically contains several important subdirectories, each serving a specific purpose. Here are some common directories found under the root directory:
Sure, here are concise purposes with examples for each directory in the Linux file system:
Purpose: Contains binaries or executables that are essential to the entire operating system you can run these binaries from the command line at any time. Examples:
cat
(concatenate and display files.)cp
(copy files and directories.)date
(display or set the system date and time.)echo
(display a line of text.)grep
(search for patterns in files.)ls
(list directory contents.)mkdir
(make directories.)mv
(move (rename) files.)rm
(remove files or directories.)chmod
(change file modes or access control lists (acls).)chown
(change file owner and group.)dd
(convert and copy a file.)df
(report file system disk space usage.)hostname
(show or set the system's hostname.)ping
(send icmp echo_request to network hosts.)ps
(report a snapshot of current processes.)pwd
(print working directory.)tar
(archive files.)uname
(print system information.)
Purpose: Contains system binaries that should only be executed by the root user, many of these binaries may share common libraries which are stored in the lib
directory.
Examples:
useradd
(adds user)mount
(attaches filesystems to directory)userdel
(deletes user)fdisk
(partition tool)fsck
(filesystem check)reboot
(reboots OS)shutdown
(shuts down OS)service
(manages system services)systemctl
(controls the systemd system (manages daemons using unit files) and service manager).
Purpose: The lib
directory in a Linux file system typically contains libraries (shared object files, .so
) that are essential for the functioning of programs and binaries located in both the /bin
and /sbin
many of these binaries may share common libraries. These libraries allow modular and efficient development and execution of software. Here's a breakdown of what you might find in the lib
directory:
- Standard Libraries: These include essential libraries like
libc.so
(C standard library),libm.so
(math library), and others that provide core functionalities needed by almost all programs. - Programming Language Libraries: Depending on the programming languages installed, you might find directories for libraries such as
libpython3.so
(Python),libperl.so
(Perl), orlibjava.so
(Java), which provide runtime support for these languages. - Graphics and GUI Libraries: Libraries like
libgtk
orlibqt
are common, providing graphical user interface (GUI) support for applications. - Database Libraries: Libraries such as
libmysqlclient.so
(MySQL client library) orlibpq.so
(PostgreSQL client library) facilitate database connectivity and operations. - Networking Libraries: These include
libcurl.so
(libcurl for URL transfers),libssl.so
(OpenSSL for secure communication), and others for networking functionalities. - Device Drivers: Some hardware-specific libraries might be found here, providing access to device-specific functionality.
- System Management Libraries: Libraries for system management and administration, such as
libudev
for device management. - Other Libraries: Depending on the specific software installed on your system, there could be numerous other libraries for specialized tasks like image processing, compression, encryption, etc.
Purpose: Files required for booting the system.
Examples: vmlinuz
(Linux kernel), grub/
(bootloader files).
Purpose: Special files representing hardware devices.
Examples: sda
(hard drive), tty1
(terminal).
Purpose: System-wide configuration files.
Examples: passwd
(user accounts), fstab
(disk mounts).
Purpose: Personal directories for each user.
Examples: /home/john
(John’s files), /home/jane
(Jane’s files).
Purpose: Mount points for removable media.
Examples: /media/usb
(USB drive), /media/cdrom
(CD-ROM).
Purpose: Temporary mount point for filesystems.
Examples: /mnt/data
(temporarily mounted data).
Purpose: The /opt
directory in Linux is used to store optional software packages and add-on applications that are not part of the standard Linux distribution. Here’s what you might find in the /opt
directory:
-
Third-Party Applications: Software installed from outside the standard package management system. Examples include:
- Web browsers like Google Chrome.
- Office suites like LibreOffice.
- Developer tools like Android Studio.
-
Proprietary Software: Commercial or proprietary software packages that are not included in the default repositories. Examples include:
- Virtualization software like VMware.
- CAD applications like AutoCAD.
-
Custom Applications: Locally developed or custom applications that are installed manually.
-
Subdirectories for Packages: Each software package installed in
/opt
usually resides in its own subdirectory. For example:/opt/google/chrome
for Google Chrome./opt/libreoffice
for LibreOffice.
-
Configuration Files: Configuration files specific to the applications installed in
/opt
. -
Documentation and Data: Any documentation, data files, or resources needed by the applications.
The /opt
directory is used to keep optional and third-party software separate from the system's default software, which helps in maintaining a clean and organized file system.
Examples: /opt/myapp
(custom application).
Purpose: The /proc
directory in Linux is a virtual filesystem that contains information about system processes and other system information. It provides a mechanism to access kernel and process-related information in a hierarchical file-like structure. Here are some key elements you can find in the /proc
directory:
- Process Directories: Each running process has a directory named after its process ID (PID). For example, the directory
/proc/1234
contains information about the process with PID 1234. Inside each process directory, you can find various files and subdirectories that provide details about the process, such as:cmdline
: The command-line arguments used to launch the process.cwd
: A symlink to the current working directory of the process.exe
: A symlink to the executable of the process.fd
: A directory containing symlinks to the file descriptors opened by the process.stat
: A file containing detailed statistics about the process.status
: A file with human-readable status information about the process.
- System Information Files: These files provide information about the overall system. Some important files include:
cpuinfo
: Information about the CPU.meminfo
: Information about memory usage.mounts
: Information about mounted filesystems.uptime
: The system uptime.version
: The Linux kernel version.
- Kernel Parameters: The
/proc/sys
directory contains files that represent kernel parameters, which can be read and modified. For example:/proc/sys/net/ipv4/ip_forward
: Controls IP forwarding./proc/sys/vm/swappiness
: Controls the tendency of the kernel to swap out memory pages.
- Other Subdirectories and Files:
/proc/bus
: Information about buses (e.g., PCI)./proc/driver
: Information about various drivers./proc/fs
: Information about filesystems./proc/interrupts
: Information about interrupt handling./proc/partitions
: Information about disk partitions./proc/slabinfo
: Information about kernel slab cache.
The /proc
filesystem provides a convenient and standardized way to access a wealth of system information and is heavily used by various system utilities and monitoring tools.
Purpose: Home directory for the root (admin) user.
Examples: .bashrc
(root’s shell settings).
Purpose: Runtime data since last boot.
Examples: utmp
(current logins), systemd/
(system data).
Purpose: Data for services provided by the system.
Examples: /srv/www
(web server files), /srv/ftp
(FTP server files).
Purpose: Virtual filesystem for hardware information.
Examples: devices/
(device info), firmware/
(firmware details).
Contains temporary files and folders are stored. Typically, files in the /tmp
directory are not meant to persist between reboots. The /tmp
directory is usually cleared out during system startup or periodically by system maintenance tasks. This is done to ensure that temporary files do not accumulate indefinitely and to reclaim disk space used by transient data, Here's a simple breakdown:
Temporary Files
: Files created by programs and users for short-term use.Temporary Folders
: Directories used to organize temporary data.Cache Files
: Temporary data stored to speed up programs.Socket Files
: Used for communication between programs on the same computer.Lock Files
: Temporary files that prevent programs from interfering with each other.
Everything in /tmp
is meant to be temporary. The system can remove these files to free up space whenever needed. Some systems may be configured to retain files in /tmp
across reboots. This can be controlled by settings in the /etc/default/tmpfs
file or similar configuration files. Many Linux distributions have mechanisms (like systemd-tmpfiles or cron jobs) to clean out /tmp at boot time or on a regular basis.
Examples: tmpfile12345
(temporary file).
Purpose: The /usr
directory in Linux contains user-related programs, utilities, libraries, documentation, and other resources that are not essential for basic system operation. Here's a breakdown in simple terms:
- Binaries (
/usr/bin
) User commands and programs that are not required for system booting or repair. Examples include:ls
: List directory contents.grep
: Search for patterns in files.firefox
: Web browser.
- System Binaries (
/usr/sbin
) System administration binaries for use by system administrators. Examples include:network-manager
: Network management daemon.apache2
: Apache HTTP Server.
- Libraries (
/usr/lib
) Shared libraries used by programs in/usr/bin
and/usr/sbin
. Examples include:libpthread.so
: POSIX threads library.libssl.so
: OpenSSL library for secure communication.
- Include Files (
/usr/include
) Header files necessary for compiling software packages. - Documentation (
/usr/share/doc
) Package documentation files. - Configuration Files (
/usr/etc
) Configuration files specific to programs in/usr/bin
and/usr/sbin
. - User Data (
/usr/share
) Architecture-independent (shared) data files for programs. Examples include:/usr/share/icons
: Icon files./usr/share/applications
: Desktop application launchers.
- Man Pages (
/usr/share/man
) Manual pages for programs and utilities.
The /usr
directory is designed to contain software that is not needed during the early stages of booting or in single-user mode but is important for normal system operation and for multiple users. It organizes user-related files separately from essential system files (/bin
, /sbin
, /lib
, etc.), promoting flexibility, ease of management, and system integrity.
Contains variable data files that are expected to change frequently during normal system operation. Here’s a breakdown of what you might find in the /var
directory:
- Logs (
/var/log
) System log files that record events and actions on the system. Examples include:syslog
: General system log.auth.log
: Authentication logs.apache2/access.log
: Apache HTTP Server access logs.
- Spool (
/var/spool
) Spooling directories for tasks waiting to be processed. Examples include:/var/spool/mail
: Mailboxes for local mail delivery./var/spool/cron
: Cron job spool directory.
- Temporary Files (
/var/tmp
) Temporary files that persist across reboots. - Run-time State (
/var/run
) Run-time information about the system since last boot. Examples include:/var/run/sshd.pid
: PID file for SSH daemon.
- Lock Files (
/var/lock
) Lock files used to indicate that a resource is in use. - Cache (
/var/cache
) Cached data files for applications. Examples include:/var/cache/apt/archives
: Cached package archives for APT.
- Libraries (
/var/lib
) State information and persistent data modified by programs. Examples include:/var/lib/mysql
: MySQL databases and server data.
- Spool for Printers and Mail (
/var/spool
) Directories for printing and mail processing. Examples include:/var/spool/cups
: Print spooler directory for CUPS.
The /var
directory is crucial for maintaining system integrity and performance by segregating dynamic data files from essential binaries and configuration files. It allows system administrators and applications to manage frequently changing data efficiently while ensuring stability and reliability of the overall system.
The Linux file system follows a hierarchical structure that starts from the root directory. This structure allows for a well-organized and standardized arrangement of files and directories, making it easier to manage and locate system files and user data.
For more detailed information, you can refer to the Filesystem Hierarchy Standard (FHS), which provides guidelines and standards for directory structures and directory contents in Unix and Unix-like operating systems.