If you’re looking for files that are larger than 10MB, 100MB or 1GB, the find command can be very helpful. With find, you can search for files based on size criteria.

Advertisement

A few days back my production application goes down. After searching for half an hour, I found the application was down due to the disk full on my server. So I searched all files greater than 1 GB and then all files greater than 100 MB. There were a few log files that were large in size, which caused the disk full.

In this tutorial, you will learn how to search file by their size using find command.

Searching the larger files in Linux

You can define size in KB, MB and GB formats. For example, you can define size 100K, 100M, 1G or 10G formats. Use below examples, which will help you to find files by there size and extension.

  • The following command will find all file greater than equals to 100MB under entire file system.
    find / -size +100M 
    

    This would search through the entire file system and return a list of all files that are larger than 100MB. If you only want to search a specific directory, you can replace “/” with the path to that directory. For example, if you only wanted to search your home directory, you could use this command:

    find ~/ -size +100M 
    
  • You can also use find to search for files that are larger than 1GB. To do this, you would just need to use a different size criterion. For example, to find all files that are greater than 1GB, you could use this command:
    find / -size +1G 
    

Find files by size and extension

Instead of searching all files, you can also search files of specific extensions greater than 1G B size. For example search, all files with extension “.log” and size are 1GB or more.

find / -type f -name "*.log" -size +1G 

Related Topics

Share.

1 Comment

  1. find / -type f -name “*.log” -size +1G

    I modified 1G in above cmd with 5G and I am getting the result which is also less than 5G because I don’t have any file more than 5G so it is showing me lesser than 5G also.

Leave A Reply