Understanding the Linux Directory Structure

I. Linux Directory Structure

Do you want to know why some programs are located under /bin, or /sbin, or /usr/bin, or /usr/sbin? For example, the less command is located under /usr/bin. Why isn’t it in /bin, or /sbin, or /usr/sbin? What are the differences between all these directories?

In this article, let’s review the Linux filesystem structure and understand the meaning of each top-level directory.

Blue: indicates a directory

Cyan: indicates a link

Black: indicates a file

 

1. / – Root
Every file and directory starts from the root directory.
Only the root user has write permission in this directory. Note that /root is the home directory of the root user, which is different from /.

 

2. /bin – User binaries
Contains binary executable files.
The common Linux commands you need to use in single-user mode are located in this directory. Commands used by all users of the system are placed here.
For example: ps, ls, ping, grep, cp

 

3. /sbin directory – System binaries
Like /bin, /sbin also contains binary executable files.
However, the Linux commands in this directory are typically used by the system administrator for system maintenance. For example: iptables, reboot, fdisk, ifconfig, swapon

 

4. /etc – Configuration files
Contains all the configuration files required by programs.
It also contains startup and shutdown shell scripts used to start/stop individual programs. For example: /etc/resolv.conf, /etc/logrotate.conf

hosts: resolves device names (or domain names) to IP addresses, equivalent to a locally available DNS function. See the images below:

 

5. /dev – Device files
Contains device files.
These include terminal devices, USB devices, or any devices connected to the system. For example: /dev/tty1, /dev/usbmon0

6、/proc – Process information
Contains information related to system processes.
This is a virtual file system that contains information about running processes. For example, the /proc/{pid} directory contains information related to a specific pid.
This is a virtual file system where system resources are represented as text information. For example: /proc/uptime

7、/var – Variable files
var stands for variable files.
This directory contains files whose contents may grow.
These include –
system log files (/var/log); package and database files (/var/lib); email (/var/mail); print queues (/var/spool); lock files (/var/lock); temporary files needed across multiple reboots (/var/tmp);

8、/tmp – Temporary files
Contains temporary files created by the system and users.
When the system restarts, all files in this directory will be deleted.

9、/usr – User programs
Contains binary files, libraries, documentation, and source code for secondary programs.
/usr/bin contains binary files for user programs. If you can’t find a user binary in /bin, look in the /usr/bin directory. For example: at, awk, cc, less, scp.
/usr/sbin contains binary files for system administrators. If you can’t find a system binary in /sbin, look in the /usr/sbin directory. For example: atd, cron, sshd, useradd, userdel.
/usr/lib contains the libraries used by /usr/bin and /usr/sbin.
/usr/local contains user programs installed from source. For example, when you install Apache from source, it will be in /usr/local/apache2.

10、/home – HOME directory
All users use the home directory to store their personal files.
For example: /home/john, /home/nikita

11、/boot – Boot loader files
Contains files related to the boot loader.
The kernel’s initrd, vmlinux, and grub files are located under /boot.
For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic

12、/lib – System libraries
Contains library files that support the binary files located under /bin and /sbin.
Library file names are ld* or lib*.so.*
For example: ld-2.11.1.so, libncurses.so.5.7

13、/opt – Optional add-on applications
opt stands for optional.
Contains add-on applications from individual vendors.
Add-on applications should be installed in /opt/ or in subdirectories under /opt/.

14、/mnt – Mount directory
A temporary mount directory where the system administrator can mount file systems.

15、/media – Removable media devices
A temporary directory used for mounting removable devices.
For example, /media/cdrom for mounting a CD-ROM, and /media/floppy for mounting a floppy drive;

16、/srv – Service data
srv stands for service.
Contains data related to site-specific services provided by the server.
For example, /srv/cvs contains data related to cvs.

 

[Reference]

Linux Filesystem Hierarchy

Source and pre-formatted versions available 1. Linux
Filesystem Hierarchy

1.1. Foreward
1.2. The Root Directory
1.3. /bin
1.4. /boot
1.5. /dev
1.6. /etc
1.7. /home
1.8. /initrd
1.9. /lib
1.10. /lost+found
1.11. /media
1.12. /mnt
1.13. /opt
1.14. /proc
1.15. /root
1.16. /sbin
1.17. /usr
1.18. /var
1.19. /srv
1.20. /tmp

Glossary A. UNIX System V Signals B. Sources C. About the
Author D. Contributors E. Disclaimer F. Donations G. Feedback H. GNU
Free Documentation License

H.1. PREAMBLE
H.2. APPLICABILITY AND DEFINITIONS
H.3. VERBATIM COPYING
H.4. COPYING IN QUANTITY
H.5. MODIFICATIONS
H.6. COMBINING DOCUMENTS
H.7. COLLECTIONS OF DOCUMENTS
H.8. AGGREGATION WITH INDEPENDENT WORKS
H.9. TRANSLATION
H.10. TERMINATION
H.11. FUTURE REVISIONS OF THIS LICENSE
H.12. ADDENDUM: How to use this License for your documents

II. Common Commands

1. Command Help
2. Users
3. SHELL
4. Display hard drive, partition, CPU, and memory information
5. Network
6. Processes
7. Files

1. Command Help
[[email protected]
~]#man ps
2. Users
$finger username  Displays information about user username
$who              Displays currently logged-in users
$who am I
$su                Become the root user
$sudo command      Execute as the root user
$passwd            Change password
3. SHELL
$history                  Displays command history in the current shell
$alias                      Displays all command aliases
$alias new_command=’command’   
Alias command as new_command
$env                       Displays all environment variables
$export var=value    Sets environment variable var to value
4. Display hard disk, partition, CPU, and memory information
$df -lh                           Displays usage status of all hard disks
$du -sh *                      
Displays the size of each directory and file in the current directory
$mount                          Displays all mounted disk partitions
$mount partition path       Mounts partition to path
$umount partition            Unmounts partition
$sudo fdisk -l                  Displays all partitions
$sudo fdisk device           
Creates a partition table for device (for example /dev/sdc). After entering, choose n, p, w
$sudo mkfs -t ext3 partition 
Formats partition patition (for example /dev/sdc1)
Modify /etc/fstab to automatically mount the partition. Add the line:
/dev/sdc1  path(mount point) ext3 defaults 0 0
$arch                            Displays architecture
$cat /proc/cpuinfo          Displays CPU information
$cat /proc/meminfo         Displays memory information
$free                            Displays memory usage
5. Network
$ifconfig     
Displays network interfaces and their corresponding IP addresses. ifconfig can also be used to configure network interfaces
$ifup eth0    Starts the eth0 interface
$ifdown eth0  Shuts down the eth0 interface
$iwconfig      Displays wireless network interfaces
$route        Displays the routing table. route can also be used to modify the routing table
$netstat      Displays the current network connection status
$ping IP      Sends ping packets to address IP
$traceroute IP Traces the route path to address IP
$dhclient     
Sends a DHCP request to a DHCP host to obtain an IP address and other configuration information.
$host domain  DNS lookup, finds the IP corresponding to domain name domain
$host IP      Reverse DNS lookup
$wget url      Uses wget to download the resource pointed to by url
$wget -m url  Mirror download
6. Processes
$top              Displays process information and updates in real time
$ps                Displays processes in the current shell
$ps -lu username  Displays processes for user username
$ps -ajx          Displays all processes in a more complete format
$kill PID          Kills process PID (PID is the Process ID)
7. Files
$touch filename   
If the file does not exist, creates an empty file; if the file exists, updates the file access and modification times.
$rm filename      Deletes a file
$cp file1 file2    Copies file1 to file2
$ls -l path        Displays files and related file information
$mkdir dir        Creates directory dir
$mkdir -p path    Recursively creates all directories in path
$rmdir dir        Deletes directory dir; dir must be empty.
$rm -r dir        Deletes directory dir and all files it contains
$file filename    Type description of file filename
$chown username:groupname filename   
Changes the file owner to owner and the group to group
$chmod 755 filenameChanges the file permissions to 755: owner r+w+x,
group: r+x, others: r+x
$od -c filename    Displays the file as ASCII characters

$cat filename      Displays a file
$cat file1 file2  Displays file1 and file2 concatenated
$head -1 filename  Displays the first line of the file
$tail -5 filename  Displays the fifth line from the end of the file
$diff file1 file2  Displays the differences between file1 and file2
$sort filename    Sorts the lines in the file and displays them
$sort -f filename  Sorts without considering case
$sort -u filename  Sorts and removes duplicate lines
$uniq filename    Displays non-repeated lines in file filename
(lines with identical content but not adjacent are not considered duplicates)
$wc filename      Counts characters, words, and lines in the file
$wc -l filename    Counts the number of lines in the file

 

Permanent updated link for this article: http://www.linuxidc.com/Linux/2016-08/134701.htm

Leave a Comment

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

中文 EN
🚀

RedGate VPN

免费节点太挤太慢?
升级高速稳定专线

立即体验 →

告别卡顿

RedGate VPN
全球高速节点

免费下载 →
Scroll to Top