How to troubleshoot when the disk space is full in Linux?
When the Linux disk space is full, you can follow the steps below to troubleshoot the issue:
- Check the disk space usage: By using the df -h command, you can display the usage of each disk partition in the system, including total space, used space, remaining space, etc. Identify the partitions with higher space usage.
- Check folder space usage: Use the command du -h –max-depth=1
to view the size of each folder in the specified directory. You can enter the larger folders one by one to continue using this command to find specific files or subfolders. - Check the log files: In a Linux system, log files can take up a lot of disk space. You can use the command du -h /var/log/ to view the size of the log folder and check for any excessively large log files.
- Delete unnecessary files and logs: If you come across any files or logs that are no longer needed, you can use the rm command to delete them. Additionally, you can use the command >
to clear a specific log file. - Check temporary files: The accumulation of temporary files may also lead to disk space issues. You can use the command ls -lh /tmp to check the size of the temporary folder and use the rm command to delete temporary files that are no longer needed.
- Check the database files: If a database server is deployed on the server, the database files may also take up a large amount of space. Utilize the database management tools to clean up unnecessary data or compress the files.
- Identify and remove invalid soft links: At times, soft links may point to files that have been deleted or moved, but the soft link itself still exists, taking up disk space. You can use the command “find -L / -type l -delete” to locate and delete these invalid soft links.
- Check for system junk files: Some system junk files may also take up disk space. You can use the ‘apt-get clean’ command to clear the APT cache, and use the ‘yum clean all’ command to clean the Yum cache.
- Check other processes: There may be some processes running that are generating a large number of temporary or log files. You can use the command lsof | grep deleted to search for files taking up a lot of disk space in these running processes.
- To increase disk space: If the previous steps do not free up enough disk space, consider expanding the disk space by using LVM or adding a new disk.
These are some common troubleshooting steps that can be selected based on the specific situation.