Check large files or folders on your Magento or Linux folders

Here is the simple tricks and number of commands to find out the disk space used on your Linux server

First of all check size of the whole server disk space by using the following simple command -:

df -h

The output should look like this -:

Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   98G   89G  9.4G  91% /
devtmpfs                 1.4G     0  1.4G   0% /dev
tmpfs                    1.4G     0  1.4G   0% /dev/shm
tmpfs                    1.4G  138M  1.3G  10% /run
tmpfs                    1.4G     0  1.4G   0% /sys/fs/cgroup
/dev/sda1                497M  197M  301M  40% /boot
tmpfs                    285M     0  285M   0% /run/user/0
tmpfs                    285M     0  285M   0% /run/user/1000

Now you can check which folders are large in size by running the following command on the root or any folder on your Linux server -:

du -cks * | sort -rn | head

The output should look like this -:

7958912 total
3043448 home
2370276 usr
2275160 var
167264  boot
83356   opt
17720   etc
1532    run
148     tmp
4       root

You can run the above command on any of the above large folders like home, usr and var.

If you want to further check top 20 folders which are larger in size then you can run the following command on the root or any folder on your Linux server -:

du -m * | sort -nr | head -n 20

The output should look like this -:

 2972 home/magento 2972 home 2471 home/magento/public_html 2315 usr 2286 var 2035 var/log 1918 home/magento/public_html/media 1859 home/magento/public_html/media/catalog 1857 home/magento/public_html/media/catalog/product 692 home/magento/public_html/media/catalog/product/cache 688 home/magento/public_html/media/catalog/product/cache/1 626 usr/share 580 usr/lib 437 usr/bin 433 home/magento/mail 390 home/magento/public_html/media/catalog/product/cache/1/thumbnail 332 usr/lib/modules 285 usr/lib64 274 home/magento/public_html/media/catalog/product/cache/1/image 262 home/magento/public_html/media/catalog/product/cache/1/thumbnail/9df78eab33525d08d6e5fb8d27136e95 

You can also check top 10 largest files in a folder or directory using the command below. It will show you all the large files, using this information you can remove the useless files to make space:-

find /home/nurissco -type f -printf "%s\t%p\n" | sort -n | tail -10

 

Change the number to 20, 30 and so on to show the number of files in the result.

Note:- You can also clear composer cache which can create some space by clearing the stored cache for composer. Please run the command below to clear composer cache.

composer clear-cache

You can list all files greater than 100MB or any size using command given below. Simply replace the size at the end to search for the files larger than that size.:-

find /home/a780846a -type f -size +100M 

That’s it, Hope this article helped you in some way. Please leave us your comment and let us know what do you think? Thanks.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.