find files larger than 100mb

How to Find Files Larger Than 100Mb in Linux

Most system administrators face the problem of low disk space sometime or the other. Some face it regularly. When there is low disk space, applications perform poorly and sometimes even stop working altogether. In such cases, it is advisable to look for big files in your system, and delete them if they are unnecessary, old or outdated. In this article, we will learn how to find files larger than 100Mb in Linux.


How to Find Files Larger Than 100Mb in Linux

Here are the steps to find large files in Linux. We will use find command for this purpose.


Find Large Files in Linux

Here is the find command to find large files in Linux.

find <location> -type f -size <size>

In the above command, we specify the location to find files after find command. We use -type option to specify that we want to find only files and not directories. We further use -size option to specify the file size. You can define the file size in Kb, Mb, and Gb using K, M or G suffixes.

Here is an example command to find files larger than 100Mb.

$ find / -type f -size +100M 

Here is the command to find files larger than 1Gb.

$ find / -type f -size +1G 


Find Files By Size and Extension

Typically, log files grow fast to a large size and cause disk to become full. You can use the above approach to find and delete large log files that are not required. Here is an example to find log files larger than 100Mb.

find / -type f -name "*.log" -size +100M 

The above command will search for all log files on your system. For example, if your log files are located in a specific directory such as /etc/nginx/log, you can instruct find command to look for the file in that location.

find /etc/nginx/log -type f -name "*.log" -size +100M


Automatically Find Large Files

If you want to regularly monitor your system for large files, you can set up a cronjob to automatically run the above find command regularly on your system. For example, run the following command to open crontab.

$ crontab -e

Add the following line to the crontab. It will run every day at 10.a.m and store the result in /home/ubuntu/large-files.txt file.

0 10 * * * find / -type f -size +100M  >/home/ubuntu/large-files.txt


Find & Remove Files

If you want to find and remove files, you can use ‘-exec rm -rf {} \’ at the end of your find command.

$ find / -type f -size +100M -exec rm -rf {} \
OR
$ find /etc/nginx/log -type f -name "*.log" -size +100M -exec rm -rf {} \

In this article, have learnt how to find large files in Linux. You can run these commands from terminal or via shell script or using cron jobs.

Also read:

How to Undo & Redo Changes in Nano Editor
How to Undo & Redo Changes in Vim/Vi Editor
How to Set Timeout in cURL
How to Set Indentation in cURL
How to Show Progress in Rsync

Leave a Reply

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