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
- If the current directory is
Important symbols
.
: Represents the current directory...
: Represents the parent directory.
Practical example
- You are in
/home/user1
.- Typing
ls ..
lists the contents of/home
. - Typing
cd ../user2
places you in/home/user2
.
- Typing
Practice
Identifying absolute paths
Among the following paths, which ones are absolute?
/etc/passwd
document.txt
/var/log/syslog
../photos
/etc/passwd
and /var/log/syslog
are absolute paths.
Navigating the file system
- From
/home/user1
, access/home/user2
using a relative path. - From
/home
, access/etc
using an absolute path.
- We'll refer to
../
to go up one level, to be in/home
, which would give the following path:../user2
. - The absolute path doesn't need to know which folder we're in, so it will be enough to refer to
/etc
.
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.