Skip to content

Linux Directory Structure Tools

A collection of commands and tools for exploring and visualizing directory structures in Linux.

Displays directory structure in a tree-like format:

Terminal window
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

Traditional directory listing:

Terminal window
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

Search and explore directories:

Terminal window
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

View directory structure with file contents:

Terminal window
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...
  • -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.