Linux Directory Structure Tools¶
A collection of commands and tools for exploring and visualizing directory structures in Linux.
Tree Command¶
Displays directory structure in a tree-like format:
sudo apt install tree -y
tree # Current directory
tree -L 2 # Limit to 2 levels
tree -d # Directories only
tree -h # Include file sizes
Example output:
.
├── documents
│ ├── work
│ └── personal
├── downloads
└── pictures
├── 2023
└── 2024
6 directories
List Command (ls)¶
Traditional directory listing:
ls -R # Recursive listing
ls -la # Detailed list with hidden files
ls -lh # Human readable sizes
Example output:
drwxr-xr-x 4 user user 4.0K Dec 22 10:30 documents
drwxr-xr-x 2 user user 4.0K Dec 22 10:30 downloads
drwxr-xr-x 4 user user 4.0K Dec 22 10:30 pictures
Find Command¶
Search and explore directories:
find . -type d # List all directories
find . -type f # List all files
find . -maxdepth 2 # Limit search depth
Example output:
.
./documents
./documents/work
./documents/personal
./downloads
./pictures
./pictures/2023
./pictures/2024
Advanced Usage: File Content Explorer¶
View directory structure with file contents:
tree -if --noreport | while read file; do
if [ -f "$file" ]; then
echo "=== $file ==="
cat "$file"
echo
fi
done
Example output:
=== ./config.yml ===
server:
port: 8080
host: localhost
=== ./readme.md ===
# Project README
This is a sample project...
Common Options¶
-a
: Show hidden files-h
: Human readable sizes-L n
: Limit depth to n levels-d
: Directories only-f
: Full path prefix
These tools are invaluable for system administration, documentation, and understanding directory hierarchies.