Combine the du and sort commands to find large files that should be deleted or moved:
$ du -ak SOURCE_DIR | sort -nrk 1 | head
The -a option makes du display the size of all the files and directories in the SOURCE_DIR. The first column of the output is the size. The -k option causes it to be displayed in kilobytes. The second column contains the file or folder name.
The -n option to sort performs a numerical sort. The -1 option specifies column 1 and the -r option reverses the sort order. The head command extracts the first ten lines from the output:
$ du -ak /home/slynux | sort -nrk 1 | head -n 4
50220 /home/slynux
43296 /home/slynux/.mozilla
43284 /home/slynux/.mozilla/firefox
43276 /home/slynux/.mozilla/firefox/8c22khxc.default
One of the drawbacks of this one-liner is that it includes directories in the result. We can improve the one-liner to output only the large files with the find command:
$ find . -type f -exec du -k {} \; | sort -nrk 1 | head
The find command selects only filenames for du to process, rather than having du traverse the filesystem to select items to report.
Note that the du command reports the number of bytes that a file requires. This is not necessarily the same as the amount of disk space the file is consuming. Space on the disk is allocated in blocks, so a 1-byte file will consume one disk block, usually between 512 and 4096 bytes.
The next section describes using the df command to determine how much space is actually available.