Linux Filesystem Cheat Sheet

High-value Linux filesystem commands for navigating, listing, inspecting, copying, moving, linking, and organizing files and directories.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Listing and Inspection
Long listing with human sizes
ls -lah

# Show detailed directory contents with human-readable sizes.

List files sorted by modification time
ls -lt

# Show newest files first.

Show directory tree to a depth
tree -L 2

# Visualize nested files and directories.

Show detailed file metadata
stat path/to/file

# Inspect inode, permissions, timestamps, and ownership.

Detect file type
file path/to/file

# Show MIME-like or content-based type information.

## Directory Creation and Removal
Create nested directories
mkdir -p app/data/uploads

# Create a directory path including missing parents.

Remove empty directory
rmdir empty-dir

# Delete a directory only if it is empty.

Remove directory recursively
rm -rf old-build

# Delete a directory and all of its contents.

## Copy, Move, Rename
Copy directory recursively with preserved metadata
cp -a source-dir target-dir

# Copy directory trees while preserving timestamps and mode when possible.

Copy interactively
cp -i source.txt dest.txt

# Prompt before overwriting an existing file.

Rename file
mv old-name.txt new-name.txt

# Rename a file or move it within the same filesystem.

Move directory
mv logs /var/archive/logs

# Move a directory to a new location.

Install file with mode
install -m 755 script.sh /usr/local/bin/script

# Copy a file and set destination permissions in one step.

## Space Usage
Directory size summary
du -sh /var/log

# Show total size for a directory in human-readable format.

Top-level sizes under current directory
du -h --max-depth=1 .

# Show one-level deep size totals.

Filesystem free space
df -h

# Display mounted filesystem capacity and usage.

Find largest files
find . -type f -printf '%s %p
' | sort -nr | head -20

# List the biggest files under a directory.

More in Linux Filesystem

No other published sheets yet.

Recommended next

No recommendations yet.