How to find large files in Linux using command line

Linux find command is used to search for files on the hard disk. A few days back, one of the partitions on my hard disk filled up to 99% with only a few hundred mega bytes  free space remaining. So I wanted to find out which files were taking up maximum space on this partition and also figure out if I can delete any of them.

In Linux, finding large files is quite easy and can be accomplished from the console using the find command as follows :

$ find <path> -size +10000k -print0 | xargs -0 ls -l

In the above find command, <path> is the path of the directory or mount point which you want to search. The + (plus) sign preceding the 10000k figure tells find that it should search for all files which are over the 10 MB size.

-print0 tells find to print the full file name on standard output followed by a null character instead of the newline character that -print uses. This allows file names that contain newlines or other types of white space to be correctly interpreted by programs that process the find output. This option corresponds to the -0 option of xargs.

The output of the find command is piped to the xargs command.

For example, to conduct the above search in the directory /media/windows on my hard drive, I can run the following command(s) :

$ find /media/windows -size +10000k -print0 | xargs -0 ls -l

So the next time you want to know which files on your hard disk are using up the most space, you can rely on the Linux find command.