Linux: Find files larger than given size (gb/mb/kb/bytes)

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

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

find <directory> -type f -size +N<Unit Type>

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.

find /usr -type f -size +4G

Output:

/usr/logs/test_1_logs.txt
/usr/logs/test_2_logs.txt

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,

find /usr -type f -size +4G -exec ls -lh {} \; | awk '{ print $9 "|| Size : " $5 }'

Output:

/usr/logs/test_1_logs.txt|| Size : 4.6G
/usr/logs/test_2_logs.txt|| Size : 7.2G

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.

find /usr -type f -size +1G

Output:

/usr/logs/error_logs.txt<br>/usr/logs/warning_logs.txt

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,

find /usr -type f -size +1G -exec ls -lh {} \; | awk '{ print $9 "|| Size : " $5 }'

Output:

/usr/logs/error_logs.txt|| Size : 1.6G
/usr/logs/warning_logs.txt|| Size : 2.2G

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.

find /usr -type f -size +500M

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:

/usr/logs/test_3_logs.txt
/usr/logs/test_4_logs.txt

To print file size along with with file paths for files larger than 500MB use this command,

find /usr -type f -size +500M -exec ls -lh {} \; | awk '{ print $9 "|| Size : " $5 }'

It will print the file paths along with size for the files larger than 500MB.

Output:

/usr/logs/test_3_logs.txt|| Size : 610G
/usr/logs/test_4_logs.txt|| Size : 712G

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.

find /usr -type f -size +100M

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,

find /usr -type f -size +100M -exec ls -lh {} \; | awk '{ print $9 "|| Size : " $5 }'

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.

find /usr -type f -size +50M

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,

find /usr -type f -size +50M -exec ls -lh {} \; | awk '{ print $9 "|| Size : " $5 }'

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.

find /usr -type f -size +0b

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,

find /usr -type f -size +0b -exec ls -lh {} \; | awk '{ print $9 "|| Size : " $5 }'

It will print the file paths along with size for the files larger than 0 bytes.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top