Find Files Based on Size in Linux

Finding files based on their size can help you figure out which files are taking up the most space on your hard drive. Whether you need to free up storage, or just want to see which files are largest, there are plenty of Linux commands that can help.

In this guide, we’ll go over the commands you can use to find files and directories based on their size in Linux. Check out some of the examples below to get started.

Find Files of Certain Size (With Commands)

Example 1. If you already know the location of the files you want to check, we can use the ls command to list files by their file size. Include the -1 option to list one file per line, the -h option to put the sizes in human-readable format, the -S option to sort the files by their size, and the -s option to show each file’s size.

$ ls -1hSs

total 16G
7.5G centos.iso
2.6G ubuntu.iso
2.4G manjaro.iso
1.9G fedora.iso
671M archlinux.iso
349M debian.iso

As you can see from the output, files are listed largest to smallest. You’ll also see a total of all file sizes on the first line of the output.

Example 2. If your files are separated into subdirectories, you can add the -R option to get files listed recursively.

$ ls -1hRSs

./arch-based:
total 3.1G
2.4G manjaro.iso
671M archlinux.iso

./debian-based:
total 2.9G
2.6G ubuntu.iso
349M debian.iso

./rhel-based:
total 9.4G
7.5G centos.iso
1.9G fedora.iso

This output shows how much space each directory is using, then lists the files (largest to smallest size) in each subdirectory.

Example 3. The find command is an even better way to list files based on their size. Let’s find files that are more than 2 GB in file size. The -size option tells find to search for files of a certain size. The + is “greater than” and 2 GB is specified as 2G in the syntax.

$ find . -size +2G

Example 4. We can also use find to search for files under a certain size. Let’s find files that are under 2 GB by using the same syntax as above, but using a - “less than” symbol instead.

$ find . -size -2G

Example 5. It’s also possible to search for files between certain sizes, by combining two -size options in find. This command will search for files between 5 GB and 10 GB.

$ find . -size +5G -size -10G

Example 6. For the best of both worlds, we can use find to search for files, and combine it with the ls command to list the size in the results, in descending order from biggest to smallest. This command will find and list files bigger than 1 GB.

$ find . -size +1G -exec ls -1hSs {} +

7.5G ./centos.iso
2.6G ./ubuntu.iso
2.4G ./manjaro.iso
1.9G ./fedora.iso

Example 7. Note that find will also search subdirectories by default.

$ find . -size +1G -exec ls -1hSs {} +

7.5G ./rhel-based/centos.iso
2.6G ./debian-based/ubuntu.iso
2.4G ./arch-based/manjaro.iso
1.9G ./rhel-based/fedora.iso

Example 8. To avoid searching subdirectories, use the -maxdepth 1 option with find.

$ find . -maxdepth 1 -size +1G -exec ls -1hSs {} +

Or, specify how deep into subdirectories you want your search to go. We could tell find that we want to search a maximum of two subdirectories deep with the -maxdepth 2 option.

$ find . -maxdepth 2 -size +1G -exec ls -1hSs {} +

Example 9. To search your entire system for the biggest files, you can use the find syntax above on the root directory. This works best with root permissions, so preface your command with sudo. This command will search your system for all files over 5 GB.

$ sudo find / -size +5G -exec ls -1hSs {} +

Example 10. If you just want a list of the largest files, use the head command in conjunction with the examples above. To see a list of the three biggest files:

$ find . -exec ls -1hSs {} + | head -3

7.5G centos.iso
2.6G ubuntu.iso
2.4G manjaro.iso

As seen in these examples, the ls and find commands are both perfect tools when you need to search for files based on their size.

Find Files of Certain Size (With GUI)

If you need to sift through a lot of files, or just don’t want to fool around with the command line, a GUI application can make it easier to find files based on their size.

There are a lot of different programs that can do the job. One that we recommend is QDirStat.

Step 1. Use the appropriate command below to install QDirStat with your system’s package manager.

Ubuntu, Debian, and Linux Mint:

$ sudo apt install qdirstat

Fedora, CentOS, AlmaLinux, and Red Hat:

$ sudo dnf install qdirstat

Arch Linux and Manjaro (install from AUR):

$ git clone https://aur.archlinux.org/qdirstat.git
$ cd qdirstat
$ makepkg -si

Step 2. Once QDirStat is installed, open the application and select where you would like the program to scan for files.

Selecting location to scan in QDirStat

Step 3. After the scan is complete, you can sort the results by file size in order to see your largest files and directories.

Sorting files and directories by their size in QDirStat

Leave a Comment

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