How to solve the insufficient disk space of the Linux system?

  Insufficient disk space is one of the very common problems in the Linux system. Once the disk space is insufficient, it will not only lead to system performance degradation, applications cannot run normally, but also cause system crashes, so we must pay great attention to it. So what are the solutions to the lack of disk space in Linux? Please see below for details.

  1. Clean up useless files

  First, find and delete useless files. This can be achieved using command line tools such as find and rm.

  For example, the following command can be used to find and delete log files that have not been used more than 1 day ago:

  find /var/log -type f -mtime +1 -exec rm {};

  Similarly, you can use the following commands to find and delete useless files above 10MB:

  find /path/to/directory -type f -size +10M -exec rm {};

  2. Delete cache files

  Cache files are data that is temporarily stored on disk and can be reused when needed. However, cache files can also take up a lot of disk space. The cache files can be deleted with the following command:

  sudo du -sh /var/cache/apt

  sudo apt clean

  This will delete the apt package manager's cache files, freeing up some disk space.

  3. Compress and archive files

  Compressing and archiving files can effectively save disk space. This can be achieved using tools such as tar and gzip.

  For example, a folder can be compressed into tar.gz format with the following command:

  tar -czvf archive.tar.gz /path/to/folder

  This will create a compressed file that takes up less disk space.

  4. Remove unnecessary software and packages

  Finding and removing unneeded software and packages can also free some disk space. Removal can be done using a package manager such as apt or yum.

  For example, use the following command to remove unwanted software:

  sudo apt remove package_name

  Or remove unwanted packages and their dependencies with:

  sudo apt autoremove package_name

  5. Expand disk space

  If the above methods cannot solve the problem, consider expanding the disk space.

Guess you like

Origin blog.csdn.net/oldboyedu1/article/details/132449217