Path Basics in Linux
Understanding File Paths in Linux
In Linux systems, file paths are essential for navigating and accessing files and directories. A path is a string of characters that specifies the unique location of a file or directory in the file system.
Types of Paths
There are two primary types of paths in Linux:
Path Type |
Description |
Example |
Absolute Path |
Starts from the root directory (/) |
/home/user/documents/file.txt |
Relative Path |
Starts from the current working directory |
./documents/file.txt |
Root Directory Structure
graph TD
A[/ Root Directory] --> B[/bin]
A --> C[/home]
A --> D[/etc]
A --> E[/var]
A --> F[/usr]
Key Path Navigation Symbols
.
(current directory)
..
(parent directory)
~
(home directory)
Basic Path Commands
## Print current working directory
pwd
## List files in current directory
ls
## Change directory
cd /path/to/directory
cd ..
cd ~
Path Resolution in Linux
When you specify a path, Linux resolves it by:
- Checking if it's an absolute path
- If relative, combining with current working directory
- Resolving special symbols like
.
and ..
Practical Example
## Create a directory structure
mkdir -p ~/LabEx/projects/demo
## Navigate using relative paths
cd ~/LabEx/projects
cd demo
pwd ## Shows /home/user/LabEx/projects/demo
By understanding these path basics, you'll be more efficient in navigating and managing files in Linux systems.