Find the biggest files and folders eating your disk
A short bash script that lists the largest files over a size limit and the largest subfolders, using find, du, sort and awk. Works on Linux and macOS.
Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?
What this changes
Read-only: it only reads file and folder sizes under DIR and prints the largest; nothing on your system is changed or deleted.
How to undo it
Nothing to undo.
When your disk is suddenly full, the first question is always “what is taking all the space?”. This script answers it in seconds without installing anything. It only reads and reports; it never deletes.
The script
#!/usr/bin/env bash
set -euo pipefail
# Usage: bigfiles.sh [DIR] [COUNT] [MIN_SIZE]
DIR=${1:-.}
COUNT=${2:-20}
MIN_SIZE=${3:-10M}
[[ -d "$DIR" ]] || { echo "not a directory: $DIR" >&2; exit 1; }
echo "== Largest files over $MIN_SIZE in $DIR =="
find "$DIR" -xdev -type f -size +"$MIN_SIZE" -exec du -k {} + 2>/dev/null \
| sort -rn \
| head -n "$COUNT" \
| awk -F'\t' '{ printf "%8.1f MB %s\n", $1/1024, $2 }'
echo
echo "== Largest folders directly inside $DIR =="
find "$DIR" -mindepth 1 -maxdepth 1 -type d -exec du -sk {} + 2>/dev/null \
| sort -rn \
| head -n "$COUNT" \
| awk -F'\t' '{ printf "%8.1f MB %s\n", $1/1024, $2 }'
Usage
chmod +x bigfiles.sh
./bigfiles.sh # current folder, top 20, files over 10 MB
./bigfiles.sh ~ 10 500M # home folder, top 10, files over 500 MB
./bigfiles.sh /var/log 15 1M # log folder, files over 1 MB
Example output:
== Largest files over 10M in big ==
25.0 MB big/videos/clip.bin
12.0 MB big/my docs/report copy.bin
== Largest folders directly inside big ==
25.0 MB big/videos
12.0 MB big/my docs
0.1 MB big/logs
How it works
Each section is a pipeline. Reading the first one stage by stage:
find "$DIR" -xdev -type f -size +"$MIN_SIZE"lists regular files bigger than the limit.-xdevstays on one filesystem, so scanning/does not wander into mounted network drives.-exec du -k {} +asksdufor each file’s size in kilobytes. The+passes many files to oneducall, which is much faster than one call per file.2>/dev/nullhides “Permission denied” messages for folders you cannot read.sort -rnsorts numerically, biggest first, andheadkeeps the top entries.awk -F'\t'splits on the tab character thatduputs between size and path, converts kilobytes to megabytes, and prints the path untouched, even if it contains spaces.
The second section uses du -sk (summary, kilobytes) on each direct subfolder, so you can see which folder to explore next. Run the script again on that folder to drill down.
Useful find size units
k= kilobytes,M= megabytes,G= gigabytes, for example+1G.+means “more than”,-means “less than”.- Combine with time:
find . -type f -size +100M -mtime +90finds big files not modified for 90 days, which are good candidates for archiving.
Usual suspects
node_modulesfolders in old projects. Find them withfind ~ -type d -name node_modules -prune.- Docker images and build cache. Check with
docker system df. - Package manager caches, old virtual machine images, video files, and logs that are never rotated.
Once you know what to remove, delete it deliberately with rm after double-checking the path. The script stays read-only on purpose. If you want an interactive view, tools like ncdu on Linux show the same information in a browsable list.
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0049 Pipes and redirection: connecting commands A pipe sends one command's output into another command, and redirection sends output to a file. Together they let small tools build… Beginner · Explains an idea · Linux, macOS Article Basics · Text processing 15 Oct 2026
- 0052 Slice and summarize text with grep, sort, uniq, cut, awk and sed A handful of classic tools can filter, count, extract and rewrite text right in the terminal. This guide shows the patterns you… Intermediate · Step by step · Linux, macOS Article Finding files & text · Text processing 15 Oct 2026
- 0421 grep, sed, awk and jq: the four text tools you will use every week A working reference for the four commands that handle most text on the command line: grep finds lines, sed edits them, awk… Intermediate · Cheat sheet · Linux, macOS Article jq & JSON on the command line · Modern command-line tools · Text processing 15 Oct 2026
- 0425 jq cheat script: pretty-print, filter and flatten JSON from a file or stdin A small read-only bash wrapper around jq with the recipes you keep looking up: pretty, compact, sorted keys, list paths, pick fields,… Beginner · Cheat sheet · Linux, macOS Script jq & JSON on the command line · Modern command-line tools · Text processing 15 Oct 2026
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +3,235 chars