Finding large and old files with find
Command-line toolAll Linux distributions
find is the standard Linux command that searches a directory tree for files matching conditions such as size, age, name or type. find / -xdev -type f -size +1G lists files larger than 1 GB on the root file system, which is often the fastest way to see what suddenly filled a disk.
1Useful tests
-size +500M (larger than 500 MiB), -mtime +30 (modified more than 30 days ago), -name '*.log', -type f (files only), -xdev (do not cross into other file systems).
2Showing sizes
Add '-exec ls -lh {} +' to see sizes, or use GNU find's -printf, for example -printf '%s %p\n', and sort the output.
3Deleting safely
-delete removes every match immediately. Run the same command without -delete first, read the list, then add -delete as the last option.
How to find files over 1 GB
- Run:
sudo find / -xdev -type f -size +1G -exec ls -lh {} + - Identify each file's owner program before removing it.
- For old logs, preview:
sudo find /var/log -type f -name '*.gz' -mtime +30 - Only then delete:
sudo find /var/log -type f -name '*.gz' -mtime +30 -delete
Cautions
- Placing -delete before the tests deletes everything under the path.
- Database, virtual-disk and swap files are large on purpose: do not delete them.
Related articles
- Disk usage with du and ncduHow to find what fills a Linux disk with du and the interactive ncdu, with options that stay on one file system.
- Inodes and 'No space left on device'What an inode is, how to see inode usage with df -i, and how to find directories with millions of small files.
- df (disk free)How to read df output, why Use% can reach 100% before Avail is zero for normal users, and how to check inodes with df -i.
Sources
Last reviewed: