When using a VPS, especially one with limited disk space, you may need to regularly clean up large files that are filling up your storage. But how do you find large files in Linux among so many folders, especially if you have a control panel installed?
If you are experiencing an overspace issue, you can follow this tutorial to easily find large files on your Linux VPS.
How to Find Large Files on a Linux VPS
For your information, it is possible that there are no large files on your VPS, but there could be a folder with thousands of small files that are consuming a lot of disk space. You may need to search for these manually.
1. SSH Login
The first step you must take is to log in via SSH. For this access, you can use applications such as PuTTY or you can also use the CMD or Terminal directly with the following command
ssh [email protected] -p 22- root: the username for your VPS login
- 192.168.1.1: your VPS IP address, or you can also use a domain name that points to your VPS IP without masking
- 22: the default VPS port. If you are using a custom port, you can change it
2. Check Available Disk Space
After logging in, you can check the remaining available disk space with the df command to check disk free or available disk space
df -h /For example, here the result shows that disk space is 100% used, meaning it is full
3. Check Folders with High Usage
Next, you can check f
du -h --max-depth=1 / 2>/dev/null | sort -rh- -h: to make the size list easier to read, for example 100M for 100MB and 1G for 1GB
- --max-depth=1: to display the folder levels
- /: the main folder path to be checked
- 2>/dev/null: to hide any potential error messages, for example, hiding the message du: cannot access ‘/proc/15428/fd/3’: No such file or directory
- sort -rh: to sort folder usage from largest to smallest
If you want to search manually, for example, if the results above show high usage in home, you can check the usage in home again and so on with the command
du -h --max-depth=1 /home 2>/dev/null | sort -rh4. Find Large Files
If you want to search for large files directly, you can use the command find. For example, to search for large files across the entire system, you can use this command
find / -type f -size +100M 2>/dev/null- /: the main folder location to be searched, subfolders will also be read
- -type f: to search for files only, without folders
- -size +100M: makes the output display only files larger than 100MB
- 2>/dev/null: hides error messages if any
- sort -rh: to sort folder usage from largest to smallest
After finding a large file, you can check its size with ll. For example, since VPS is generally used for websites and files are in public_html, you can check the /home/wpgan.com/public_html/ folder first
ll -h /home/wpgan.com/public_html/Alternatively, you can also use a combined find and du command for a faster search
find / -type f -size +100M -exec du -h {} + 2>/dev/null5. Delete Files or Folders
Once you have found a file or folder that is using a lot of disk space, you can download it first using SCP or you can also use RSYNC if you feel the file is important.
If it has been downloaded, you can use the rm command to delete the file, for example
rm -r /home/wpgan.com/public_html/error_logAfter deleting the file, you can recheck the disk space usage on your VPS starting from the beginning of this tutorial, and the results will look like this
That is an easy way to check and delete large files on a VPS, so your VPS can continue to run without issues caused by full disk space.
COMMENTS
Loading...