find files in linux

How to Find Files Larger Than 1GB

Sometimes you may need to find files that are larger than specific file size. This is a common requirement in case you are running out of disk space. In such cases, system administrators tend to find and delete the largest files to quickly free up some space. In this article, we will look at how to find files that are larger than 1GB on your Linux system. Once you have a list of such files, you can clear them or delete them as per your requirement.

How to Find Files Larger Than 1GB

We will use find command to find files according to various criteria.

Find Large Files in Linux

Find command allows you to find files based on their size using -size command. Here is the command to find all files on your disk, that are larger than 1GB.

$ find / -type f -size +1G 

In the above command we use / to tell find command to start looking from / folder. You may change the search location as per your requirement. We use ‘-type f’ to specify that we are looking for files only, and not directories. ‘-size +1G’ indicates that we are searching for files larger than 1GB. You may use K,M,G to specify files sizes in Kb, Mb and Gb formats.

Here is the command to find files larger than 100Mb.

$ find / -type f -size +100M 

Find Large Files by Name or Extension

If you want to further filter your search criteria, you can also use -name option to find files by name or extension. Here is a find command to find only log files that are larger than 1GB size.

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

If you want to regularly find large log files that are larger than specific size then you can create a cron job that regularly runs the find command and redirects output to a text file for further reference. Open crontab in text editor.

$ crontab -e

Add the following line to it.

0 10 1 * * find / -type f -name "*.log" -size +1G  >/home/ubuntu/big_files.txt

Save and close the file. The above cron job will run at 10.a.m on 1st of every month, get a list of .log files larger than 1GB in size and send the output to /home/ubuntu/big_files.txt. You can clear or remove these files as per your requirement.

In this article, we have learnt how to find files larger than specific size in Linux.

Also read:

How to Compare Two Files in Linux
How to Use Strace Command in Linux
Shell Script to Check Disk Space and Send Email Alerts
Shell Script to Check Memory and Send Email Alerts
Linux Split File into Multiple Files

Leave a Reply

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