Finding files that use the most disk space
Is it possible to list the largest files on my hard drive? I frequently use
df -Hto display my disk usage, but this only gives the percentage full, GBs remaining, etc.
I do a lot of data-intensive calculations, with a large number of small files and a very small number of very large files. Since most of my disk space used is in a very small number of files, it can be difficult to track down where these large files are. Deleting a 1 kB file does not free much space, but deleting a 100 GB file does. Is there any way to sort the files on the hard drive in terms of their size?
With standard available tools:
To list the top 10 largest files from the current directory:
du . | sort -nr | head -n10
To list the largest directories from the current directory:
du -s * | sort -nr | head -n10
UPDATE These days I usually use a more readable form (as Jay Chakra explains in another answer and leave off the
| head -n10, simply let it scroll off the screen. The last line has the largest file or directory (tree).
Sometimes, eg. when you have lots of mount points in the current directory, instead of using
--exclude=PATTERN, it is handier to mount the filesystem on an unused mount point (often
/mnt) and work from there.
Mind you that when working with large (NFS) volumes, you can cause a substantial load on the storage backend (filer) when running
duover lots of (sub)directories. In that case it is better to consider setting
quotaon the volume.