File System

File system organization

The file system under Linux follows a hierarchical structure in the form of an inverted tree. Everything starts at the root represented by /.

Basic structure

Here are some important directories generally found at the root:

  • /bin: Contains essential programs accessible by all users.
  • /etc: Contains system configuration files.
  • /home: Contains users' personal folders.
  • /var: Contains variable files like system logs.
  • /tmp: Directory for temporary files.
  • /usr: Contains additional programs and files.
Each directory has a specific function and can contain subdirectories or files.

Hierarchy example

Here's a simplified representation:

/
|-- bin
|-- etc
|-- home
|   |-- user1
|   |-- user2
|-- var
|-- tmp
|-- usr

Paths in the file system

A path designates the location of a file or directory in the system.

Absolute path

An absolute path always starts from the root (/) and specifies the exact location.

  • Example:
    • /home/user1/document.txt
    • /etc/hosts

Relative path

A relative path is defined relative to the current directory (where you are in the system).

  • Example:
    • If the current directory is /home/user1:
      • document.txt refers to /home/user1/document.txt
      • ../user2 refers to /home/user2

Important symbols

  • .: Represents the current directory.
  • ..: Represents the parent directory.

Practical example

  1. You are in /home/user1.
    • Typing ls .. lists the contents of /home.
    • Typing cd ../user2 places you in /home/user2.

Practice

Identifying absolute paths

Among the following paths, which ones are absolute?

  • /etc/passwd
  • document.txt
  • /var/log/syslog
  • ../photos
  1. From /home/user1, access /home/user2 using a relative path.
  2. From /home, access /etc using an absolute path.

Summary

  • The Linux file system is organized hierarchically with a root /.
  • An absolute path always starts with /.
  • A relative path depends on the current directory and uses . or .. to navigate.