This blog post will teach you how to use find command to find files by size in Linux. You will learn how to use the -size option to specify the size criteria, and how to use various other options to filter the results.
- Many find criteria take numeric values
- find -size 10M
- Files with a size of exactly 10 megabytes
- find -size +10M
- Files with a size over 10 megabytes
- find -size -10M
- Files with a size less than 10 megabytes
- Other modifiers are available such as k for KB, G for GB, etc.
find can search your system for files that comply with certain numeric criteria such as the size of the file (-size), the number of links to the file (-links) the date of the last change to the file’s data, (-mtime), date of the last change to the file’s medtadata (-ctime) or the date of the last time the file was read (-atime). All of thse criteria accept a numeric value. When you provide numeric values to find you can look for an exact match, more than the number, or lells than the number. For example:
[user@user-pc ~]$ find / -atime 5
looks for files on the system whose last accessed time stamp (see the next slide for more information on -atime) is exactly five days ago, whereas:
[user@user-pc ~]$ find / -atime +5
will find files whose last accessed time stamp is more than five days ago. Lastly:
[user@user-pc ~]$ find / -atime -5
will print the list of files whose last accessed time stamp is less than five days ago.
Other size modifiers can be used such as M and G. Be warned, however, that these modifiers round everything up to the single unit. Thus find -size 1M will show files smaller than 1 MB because it rounds all files up to 1 MB