Linux Directory Basics
Understanding Linux Directory Structure
In Linux, directories are fundamental to organizing and managing files. The directory structure follows a hierarchical tree-like system, with the root directory /
serving as the top-level entry point.
Key Directory Concepts
graph TD
A[Root Directory /] --> B[Home Directories]
A --> C[System Directories]
A --> D[User Directories]
Root Directory Hierarchy
Directory |
Purpose |
/home |
User home directories |
/etc |
System configuration files |
/var |
Variable data files |
/bin |
Essential user binaries |
/usr |
User utilities and applications |
Basic Directory Navigation Commands
To explore and manage directories, Linux provides several essential commands:
pwd (Print Working Directory)
$ pwd
/home/labex/workspace
ls (List Directory Contents)
## List files and directories
$ ls
## Detailed listing
$ ls -l
## Show hidden files
$ ls -a
cd (Change Directory)
## Move to home directory
$ cd ~
## Move to parent directory
$ cd ..
## Move to specific directory
$ cd /path/to/directory
Directory Permissions
Linux uses a robust permission system to control access:
$ ls -l
drwxr-xr-x 2 labex users 4096 Jun 1 10:00 documents
Permission breakdown:
- First character: Directory type
- Next 3 characters: Owner permissions
- Next 3 characters: Group permissions
- Last 3 characters: Others permissions
Creating and Removing Directories
mkdir (Make Directory)
## Create a single directory
$ mkdir new_folder
## Create nested directories
$ mkdir -p project/src/main
rmdir and rm (Remove Directories)
## Remove empty directory
$ rmdir empty_folder
## Remove directory with contents
$ rm -r folder_with_contents
Best Practices
- Use descriptive directory names
- Maintain a logical directory structure
- Be cautious with recursive delete commands
- Understand permission implications
By mastering these Linux directory basics, users can efficiently navigate, manage, and organize their file systems. LaBEx recommends practicing these commands to build confidence in Linux file management.