to find files bigger than 4096 bytes.
to find files smaller than 4096 bytes.
Notice the + and - difference after the size switch.
ow 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
If you want more human readable output try (GNU user only):
$ cd /path/to/some/where
$ du -hsx * | sort -rh | head -10
- 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):
Find the largest file in a directory and its subdirectories using the find command
Type the following GNU/find command:
You can skip directories and only display files, type:
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: