A Way to Find Files That Are Too Large on Linux RHEL 7

A Way to Find Files That Are Too Large on Linux RHEL 7
A Way to Find Files That Are Too Large on Linux RHEL 7

A Way to Find Files That Are Too Large on Linux RHEL 7 - Hello everyone, welcome to the kitsake.com blog. I hope you are all doing well and always blessed with ease in everything, be it in life or work. Amin.

This time I will share a way to find files that are too large and take up server disk space. I usually use this method to find and delete these large files.

It's hazardous when the hard disk on the server is entire, especially up to 100% and it's on the root partition.

Searching for files with a large size using the 'find' command.

Now, the first thing you do is use the basic linux command, which is the 'find' command. With the addition of some options and requirements to make the file search more specific.

Below is the 'find' command that I've provided with several options in it. You can use it as is or customize it yourself.

More than 100 MB 

To find large files, you can write the command below:

# find / -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

More than 500 MB

Or you want to enlarge the size you want to find, you can increase the size, for example:

# find / -type f -size +500M -exec ls -lh {} \; | awk '{ print $NF ": " $5 }'

Find Large Files
Find Large Files

In the image above is the result of the search for large files using the 'find' command, which has been successfully displayed.

Deleting excessively large files after they are found using the 'find' command.

Below, I illustrate two options for managing the server to ensure that the hard disk capacity is maintained. These options involve either emptying the contents of files or deleting large files. These large files are obtained using the 'find' command that we executed earlier.

'cat' command

If the file found is a log and you want to empty the file without deleting it you can use this command:

# cat /dev/null > /var/log/nginx.log

'rm' command

And when you want to delete the file, just delete the file that takes up the size on the partition:

# rm /root/zend-server.tgz

You just have to see the results of your cleansing, whether they are appropriate or still lacking and need to be cleaned again. 

# df -h
Delete File
Delete File

If it's considered sufficient for the hard disk within RedHat 7 OS to be less than 80% full in terms of its usage, I believe that's adequate. However, if you want to prolong the duration between activities like cleansing, you can clean up large files thoroughly.

Closing statement

Yes, that's how I search for excessively large files, which can lead to the disk usage on the Red Hat Linux server becoming full. Once the files are located, we can address the issue by either deleting or moving the files according to your policies.

Perhaps that's the extent of what I can share with you all. Hopefully, this article will prove to be helpful.

Thank you.

Bangkit Ade Saputra
Bangkit Ade Saputra At the end of the day, my job involves people. we're complicated, we're always changing, we have millions of things going on in our lives, and changing jobs is always a big decision.

Post a Comment for "A Way to Find Files That Are Too Large on Linux RHEL 7"