</> Snippet
NAVIGATION
HomeSnippets
ACTIONS
Bash#bash#sysadmin

Find large files

List the biggest files under a directory, human-readable sizes.

26d ago·167 views·9 lines
large_files.sh9 lines
Raw Download
1#!/usr/bin/env bash
2set -euo pipefail
3
4DIR="${1:-.}"
5find "$DIR" -type f -printf '%s\t%p\n' \
6 | sort -rn \
7 | head -20 \
8 | awk '{ printf "%.1f MB\t%s\n", $1/1048576, $2 }'
9
README.md

Find large files

Pass a directory as the first argument (defaults to the current one). Prints the 20 largest files with sizes in megabytes.