In this article, we will discuss how to recursively find files which are larger than a given size in Linux, using the find command.
Table of Contents
- Syntax of find command to find files bigger than given size in Linux.
- Find files larger than 4gb in Linux.
- Find files larger than 1gb in Linux.
- Find files larger than 500 MB in Linux.
- Find files larger than 100 MB in Linux.
- Find files larger than 100 MB in Linux.
- Find files larger than 0 Bytes in Linux.
Many times we encounter a situation where we need to find huge files in Linux. These files can be log files or some other kind of data files. In such scenarios we need to search files by size. For this, we can easily use the find command in Linux.
The find command in Linux provides an easy way to search files recursively in a directory hierarchy. It also provides various options to do the selective search. One such option is “-size”, it helps to recursively search files by size.
Syntax of find command to find files bigger than given size in Linux
In the given , it will recursively search for the files whose size is greater than N. Here N is a number and along with it we can specify size unit type like,
- G-> for gibibytes
- M-> for megabytes
- K-> for kibibytes
- b-> for bytes
For example, “-size +4G” makes the find command to search for files greater than 4GB. Here, + sign is denote that look for files greater than or equal to N[Type], like in this case, -size +4G will make find command to look for files bigger than 4GB.
Let’s see some detailed examples of finding files greater than a given size,
Find files larger than 4gb in Linux
To find files larger than 4GB, we need to pass the -size option with value +4G in the find command.
Output:
It recursively searched for files inside the folder “/usr” and filtered out the files with size larger than or equal to 4GB, then printed the paths of such files.
The previous command just printed the file paths which are greater than 4GB. If you want print the size along with file name then use this command,
Output:
Find files larger than 1gb in Linux
To find files larger than 1GB, we need to pass the -size option with value +1G in the find command.
Output:
It recursively searched for files inside the folder “/usr/” and filtered out the files with size larger than or equal to 1GB, then printed the paths of such files.
The previous command just printed the file paths which are greater than 1GB. If you want print the size along with file name then use this command,
Output:
Find files larger than 500mb in Linux
To find files larger than 500 MB, we need to pass the -size option with value +500M in the find command.
It will recursively search for the files inside the folder “/usr/” and filter out the files with size larger than or equal to 500MB, then print the paths of each such files.
Output:
To print file size along with with file paths for files larger than 500MB use this command,
It will print the file paths along with size for the files larger than 500MB.
Output:
Find files larger than 100mb in Linux
To find files larger than 100 MB, we need to pass the -size option with value +100M in the find command.
It will recursively search for the files inside the folder “/usr/” and filter out the files with size larger than or equal to 100MB, then print the paths of each such files. To print file size along with with file paths for files larger than 100MB use this command,
It will print the file paths along with size for the files larger than 100MB.
Find files larger than 50mb in Linux
To find files larger than 50 MB, we need to pass the -size option with value +50M in the find command.
It will recursively search for the files inside the folder “/usr/” and filter out the files with size larger than or equal to 50MB, then print the paths of each such files. To print file size along with with file paths for files larger than 50MB use this command,
It will print the file paths along with size for the files larger than 50MB.
Find files larger than 0 bytes in Linux
To find files larger than 0 Bytes, we need to pass the -size option with value +0b in the find command.
It will recursively search for the files inside the folder “/usr/” and filter out the files with size larger than or equal to 0 Bytes, then print the paths of each such files. To print file size along with with file paths for files larger than 0 Bytes use this command,
It will print the file paths along with size for the files larger than 0 bytes.