How to find folders and files by size linux (terminal)
How to find folders and files by size linux (terminal)

How to find folders and files by size linux (terminal)

Advertisment
When you are hosting websites, you might find accounts with a huge disk usage and it could be very painful to find where the biggest files or directories are. This is a great tool to find them quickly

First connect through SSH as root. 

Then go to a folder where you want to start the search from, for example in my case it is home

cd ..
cd home

Then run the following script, you can modify the parameters, the directory /home/ is where we will start looking from and -20 ,means that we want to find -20 at a time, the more you show the longer it will take.

 

# du -ah <folder_path> | sort -rhk 1 | head -n 20

 

If you are using Apache and cPanel you might find folders named virtfs with high disk usage, do not erase them skip them.

What is virtfs in cPanel ?

These folders are created when you have jailshell enabled, jail shell increases security by separating the ssh accesses allowed to each user / account in your server.

To skip that directory or any other directory that you don't want to scan use the --exclude parameter and add the "value" of the folder of tile you want to exclude.

 

du -ah <folder_path> --exclude="virtfs" | sort -rhk 1 | head -n 20

 

If this was helpful or even if you encountered some trouble leave us a comment. 

Good Luck!

 

Comments

Get a Quote

Get a Quote