How To Find Largest Top 10 Files and Directories On Linux / UNIX / BSD find
Use:
find . -type f -size +4096c
to find files bigger than 4096 bytes.
And :
find . -type f -size -4096c
to find files smaller than 4096 bytes.
Notice the + and - difference after the size switch.
The -size
switch explained:
-size n[cwbkMG]
File uses n units of space. The following suffixes can be used:
`b' for 512-byte blocks (this is the default if no suffix is
used)
`c' for bytes
`w' for two-byte words
`k' for Kilobytes (units of 1024 bytes)
`M' for Megabytes (units of 1048576 bytes)
`G' for Gigabytes (units of 1073741824 bytes)
The size does not count indirect blocks, but it does count
blocks in sparse files that are not actually allocated. Bear in
mind that the `%k' and `%b' format specifiers of -printf handle
sparse files differently. The `b' suffix always denotes
512-byte blocks and never 1 Kilobyte blocks, which is different
to the behaviour of -ls.
How To Find Largest Top 10 Files and Directories On Linux / UNIX / BSD
last updated in BASH Shell, CentOS, Debian / Ubuntu, File system,FreeBSD, Linux, UNIXHow do I find the largest top files and directories on a Linux or Unix-like operating systems?
Sometimes it is necessary to know what file(s) or directories are eating up all your disk space. Further, it may be required to find out it at the particular directory location on filesystem such as /tmp/ or /var/ or /home/. This guide will help you to use Unix and Linux command for finding the largest or biggest the files or directories on filesystem.
How to find out top 10 files and directories on Linux or Unix
There is no simple command available to find out the largest files/directories on a Linux/UNIX/BSD filesystem. However, combination of following three commands (using pipes) you can easily find out list of largest files: Steps to find Largest Directories in Linux
- du command : Estimate file space usage.
- sort command : Sort lines of text files or given input data.
- head command : Output the first part of files i.e. to display first 10 largest file.
- find command : Search file.
How to find out top Directories and files in Linux
Type the following command at the shell prompt to find out top 10 largest file/directories:# du -a /var | sort -n -r | head -n 10
Sample outputs:
1008372 /var 313236 /var/www 253964 /var/log 192544 /var/lib 152628 /var/spool 152508 /var/spool/squid 136524 /var/spool/squid/00 95736 /var/log/mrtg.log 74688 /var/log/squid 62544 /var/cache
If you want more human readable output try (GNU user only):$ cd /path/to/some/where
$ du -hsx * | sort -rh | head -10
Where,
- du command -h option : display sizes in human readable format (e.g., 1K, 234M, 2G).
- du command -s option : show only a total for each argument (summary).
- du command -x option : skip directories on different file systems.
- sort command -r option : reverse the result of comparisons.
- sort command -h option : compare human readable numbers. This is GNU sort specific option only.
- head command -10 OR -n 10 option : show the first 10 lines.
The above command will only work of GNU/sort is installed. Other Unix like operating system should use the following version (see comments below):
Sample outputs:
179M . 84M ./uploads 57M ./images 51M ./images/faq 49M ./images/faq/2013 48M ./uploads/cms 37M ./videos/faq/2013/12 37M ./videos/faq/2013 37M ./videos/faq 37M ./videos 36M ./uploads/faq
Find the largest file in a directory and its subdirectories using the find command
Type the following GNU/find command:
Sample outputs:
5700875 ./images/faq/2013/11/iftop-outputs.gif 5459671 ./videos/faq/2013/12/glances/glances.webm 5091119 ./videos/faq/2013/12/glances/glances.ogv 4706278 ./images/faq/2013/09/cyberciti.biz.linux.wallpapers_r0x1.tar.gz 3911341 ./videos/faq/2013/12/vim-exit/vim-exit.ogv 3640181 ./videos/faq/2013/12/python-subprocess/python-subprocess.webm 3571712 ./images/faq/2013/12/glances-demo-large.gif 3222684 ./videos/faq/2013/12/vim-exit/vim-exit.mp4 3198164 ./videos/faq/2013/12/python-subprocess/python-subprocess.ogv 3056537 ./images/faq/2013/08/debian-as-parent-distribution.png.bak
You can skip directories and only display files, type:
OR
For example, to find files which are bigger than 4MB, use the following command:
To find files smaller than 4MB, use this command:
You might wonder how to find files between a certain size. For instance, you can find files between 30MB and 40MB using the following command:
To find files of exact size, for example 30MB, run: