Master Linux Disk Space: Quick Commands to Find and Clean Large Files
Learn how to efficiently locate and manage large files on Linux using powerful commands such as du, find, ls, and the visual tool ncdu, with step-by-step examples, sorting techniques, and practical tips for cleaning up disk space.
In Linux, managing disk space is essential; when the disk fills up, you need to locate large files, clean unnecessary ones, and identify space hogs. This article presents efficient methods.
1. Use du to view directory/file sizes
The du command reports disk usage of files and directories, traversing them to calculate sizes. Example to display current directory and subdirectories: du -h . To list only top-level subdirectories sorted by size:
du -h --max-depth=1 . | sort -hr | head -n 10 -h: human‑readable format (KB, MB, GB). sort -hr: sort by size in reverse order, handling human‑readable units. --max-depth=1: limit output to one level deep.
2. Find large files with find
Use find to search for files exceeding a size threshold, e.g., larger than 100 MB:
find . -type f -size +100M -type f: search only regular files. -size +100M: match files larger than 100 MB (use - for smaller, units like M, G, k).
3. List large files with ls
The ls command can sort files by size using -S and display human‑readable sizes with -lh. Example to show the top 10 largest files:
ls -lhS . | head -n 10 -l: long listing format. -h: human‑readable sizes. -S: sort by size (largest first).
To list the five biggest files:
ls -lhS | head -n 54. Visual inspection with ncdu
ncduprovides an interactive, visual view of disk usage. Install it first:
sudo apt install ncdu # Debian/Ubuntu
sudo yum install ncdu # CentOS/RHELRun the tool on a directory, e.g., your home folder: sudo ncdu /home/user The interface shows directories with size bars, allowing navigation with Enter, back with Backspace, and deletion with d (use caution).
5. Summary
Disk space management is a common operations task; the commands above— du, find, ls, and ncdu —cover typical use cases for locating and cleaning large files.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
