Home FAQ How To Find Files Bigger Or Smaller Than X Size In Linux
Find Files Bigger Or Smaller Than X Size In Linux

How To Find Files Bigger Or Smaller Than X Size In Linux

By sk
2830 Views

Let us say you want to find files which are less than or greater than a certain size in your system. How would  you do that? Manually check each and every file's size? No, a good system admin won't do it. There is always an easiest and fastest way to do things in Linux. This brief tutorial covers how to find files bigger or smaller than X size in Linux and Unix operating systems.

Find Files Bigger Or Smaller Than X Size

Using find command, we can also easily find files bigger or smaller than given size.

For instance, to find files that are bigger than 4GB in a directory, just enter:

$ find . -type f -size +4G

Sample output from my system:

./VirtualBox VMs/Ubuntu 16.04 LTS Desktop/Ubuntu 16.04 LTS Desktop.vdi
./VirtualBox VMs/Ubuntu 16.04 Server/Ubuntu 16.04 Server.vdi
./Soft_Backup/VHD's/Antergos/Antergos.vdi
./Soft_Backup/VHD's/FreeBSD 10.3 MATE desktop/FreeBSD 10.3 MATE desktop.vdi
./Soft_Backup/VHD's/Fedora 23 desktop/Fedora 23 desktop.vdi
./Soft_Backup/VHD's/Fedora 23 desktop/.goutputstream-UT19IY
./Soft_Backup/VHD's/openSUSE 42.1 Leap Desktop/openSUSE 42.1 Leap Desktop.vdi
./Soft_Backup/VHD's/Ubuntu 17.04 server/Ubuntu 17.04 server.vdi
./Soft_Backup/VHD's/Fedora 23_/Fedora 23 .vdi
./Soft_Backup/VHD's/Ubuntu 16.04 LTS Desktop/Ubuntu 16.04 LTS Desktop.vdi
./Soft_Backup/VHD's/Ubuntu 14.04 LTS desktop/Ubuntu 14.04 LTS desktop.vdi
./Soft_Backup/VHD's/Debian 8 Desktop/Debian 8 Desktop.vdi
./Soft_Backup/VHD's/FreeBSD 10.3 server/FreeBSD 10.3 server.vdi
./Soft_Backup/VHD's/OpenMandriva Lx 3 desktop/OpenMandriva Lx 3 desktop.vdi
./Soft_Backup/VHD's/Elementary OS_/Elementary OS_.vdi
./Soft_Backup/OS Images/Linux/openSUSE-Leap-42.1-DVD-x86_64.iso/openSUSE-Leap-42.1-DVD-x86_64.iso
[...]

As you can see, I have some files with size bigger than 4GiB. Here, the dot (.) indicates the current directory.

To search for files bigger than 4 GiB in the entire filesystem, run:

$ find / -type f -size +4G

To know files bigger than X size in a specific directory, replace the dot (.) in the above command with the directory path like below.

$ find Downloads/ -type f -size +4G

The above command find files bigger than 4 GiB in Downloads directory.

Similarly, to find the files which are smaller than X size, for example 4GiB, use the following command:

$ find . -type f -size -4G

You can use size switch for other formats, such as

  • `c' for bytes
  • 'w' for two-byte words
  • `k' for Kilobytes
  • `M' for Megabytes
  • `G' for Gigabytes

For example, to find files which are bigger than 4MB, use the following command:

$ find . -type f -size +4M

To find files smaller than 4MB, use this command:

$ find . -type f -size -4M

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:

$ find -size +30M -size -40M

To find files of exact size, for example 30MB, run:

$ find -size 30M

For more details, refer man pages.

$ man find

Update:

As one of the reader mentioned in the comment section below, the find command can also display a long listing of all the files it finds by using the -exec switch. The command below will find all of the files between 30M and 40M, and display a long listing of each file.

$ find . -type f -size +30M -size -40M -exec ls -l {} +

Recommended Read:


Do you know any other useful and easiest way to find files which are smaller or bigger than a particular size? Please feel free to comment them in comment section below.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

4 comments

MyDisqussion October 2, 2017 - 6:58 pm

The find command can also display a long listing of all the files it finds by using the -exec switch. The command below will find all of the files between 30M and 40M, and display a long listing of each file.

find . -type f -size +30M -size -40M -exec ls -l {} +

Reply
SK October 2, 2017 - 7:26 pm

You, sir, are a genius. Thanks. I didn’t know it earlier.

Reply
Hugo May 24, 2020 - 7:56 pm

“Here, the dot (.) represents the whole file system.”
is not correct. The dot stands for the actual folder you launch the find command from. For the whole file system you have to use:
$ find / -type f -size +4G

Reply
sk May 24, 2020 - 8:54 pm

Yes, you are right. Thanks. Corrected now.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

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

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More