How to Quickly Find and Clean Large Files on Linux
This guide shows several efficient Linux commands—du, find, ls, and ncdu—to locate large files, sort results, and safely remove unnecessary data, helping you manage disk space before it runs out.
Method 1: Using du to view directory/file sizes
The du command reports disk usage for files and directories. A basic usage is: du -h . To list only the top‑level subdirectories in a human‑readable format and sort them by size, combine it with sort and head:
du -h --max-depth=1 . | sort -hr | head -n 10 -h: display sizes in KB/MB/GB. --max-depth=1: limit output to one level of subdirectories. sort -hr: sort numerically in reverse order, respecting human‑readable units.
Method 2: Using find to locate large files
The find utility can search for files exceeding a given size. For example, to find files larger than 100 MiB in the current directory tree:
find . -type f -size +100M -type f: restrict the search to regular files. -size +100M: match files larger than 100 MiB (use - for smaller, and units like k, G are also supported).
Method 3: Using ls to list large files
The ls command can sort files by size with the -S flag and show human‑readable sizes with -lh. To display the ten biggest entries: ls -lhS . | head -n 10 Example to list the top five largest files:
ls -lhS | head -n 5 -l: long listing format. -h: human‑readable sizes. -S: sort by size, largest first.
Method 4: Using ncdu for an interactive view
ncduprovides a curses‑based visual interface for disk usage analysis. Install it first:
sudo apt install ncdu # Debian/Ubuntu sudo yum install ncdu # CentOS/RHELOptionally create an alias to replace the default du output with ncdu:
alias du="ncdu --color dark -rr -x --exclude .git --exclude node_modules"Run the tool on a directory, e.g.: sudo ncdu /home/user The interface shows a tree of directories with size bars. Navigation:
Enter: drill down into a directory.
Left arrow or Backspace: go up one level. d: delete the selected file or directory (use with caution).
Conclusion
Effective disk‑space management is a routine operations task. The commands above— du, find, ls, and ncdu —cover most scenarios for locating and cleaning large files on a Linux system.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
