Skip to content

3. File System

3.1 Directory Structure Overview

Linux follows the everything is a file philosophy. All content (including hardware devices) exists as files. The entire file system starts from / (root directory), forming an inverted tree.

bash
# View root directory structure
ls /
bash
bin  boot  dev  etc  home  lib  lib64  lost+found  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
DirectoryFull NamePurpose
/rootRoot directory, the starting point of all directories
/binbinariesBasic user commands (ls, cp, mv, etc.)
/sbinsystem binariesSystem administration commands (fdisk, iptables, etc.)
/etcetceteraSystem configuration files (equivalent to Windows Control Panel)
/homehomeHome directories for regular users
/rootroot homeHome directory for the root user
/varvariableVariable data (logs, caches, mail, etc.)
/tmptemporaryTemporary files (may be cleared on reboot)
/usrUnix System ResourcesUser-level programs and data (the largest directory)
/optoptionalThird-party software installation location
/procprocessVirtual filesystem for process and kernel information
/devdeviceDevice files (hard drives, terminals, etc.)
/bootbootBoot loader files (kernel, grub)
/mntmountTemporary mount points
/liblibrarySystem shared library files

📝 Note: 📝 Memory trick: /etc can be understood as "Editable Text Configuration" — this is the easiest interpretation to remember.

3.2 Absolute Paths and Relative Paths

Absolute Path: a complete path starting from /, such as /home/user/Documents

Relative Path: a path relative to the current directory, not starting with /

Three special directory symbols:

  • . — current directory
  • .. — parent directory
  • ~ — current user's home directory
bash
# Assuming we're currently in /home/user, the following two methods are equivalent
cd /home/user/Documents        # Absolute path
cd Documents                   # Relative path

# Go to parent directory
cd ..

# Go up two directory levels
cd ../..

# Go to home directory (three equivalent methods)
cd ~
cd
cd $HOME

3.3 File Types

In Linux, everything is a file. File types are identified by the first character of ls -l output:

bash
ls -l /
bash
drwxr-xr-x   2 root root  4096 Dec 15 08:00 bin
drwxr-xr-x   3 root root  4096 Dec 15 08:00 boot
drwxr-xr-x  18 root root  3800 Jun 20 10:00 dev
drwxr-xr-x  96 root root  4096 Jun 20 10:00 etc
drwxr-xr-x   4 root root  4096 Jan 10 14:30 home
lrwxrwxrwx   1 root root     7 Dec 15 08:00 lib -> usr/lib
-rw-r--r--   1 root root    64 Jun 20 09:00 test.txt
IdentifierTypeDescription
-Regular fileText, binary, images, etc.
dDirectoryFolder
lSymbolic linkSimilar to Windows shortcuts
cCharacter deviceTerminals, keyboards, etc.
bBlock deviceHard drives, USB drives, etc.
pNamed pipeInter-process communication
sSocketNetwork communication

Other Ways to View File Types:

bash
file /bin/ls
file /etc/passwd
file /dev/sda
bash
/bin/ls:        ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, ...
/etc/passwd:    ASCII text
/dev/sda:       block special (8/0)