1

What are some generic ways to free up lots of storage space without deleting personal files?

I'm doing a distro upgrade (Debian11->12) and it needs lots of disk space on the root partition / which doesn't have a large size and I'd like to keep all user files on that partition with few exceptions if needed. A prior upgrade failed in the middle of it because of the error No space left on device and required more disk space than what was displayed when running for example sudo apt-get full-upgrade. Running step-wise distro upgrades that each require less disk space is not yet possible.

Generic ways would be deleting caches and old logs rather than moving or deleting user files such as media files. Please include explanations what these things delete.

1
  • run ncdu under various folders on the root partition to understand where the space is being used up. Then decide accordingly, for example {if you were on redhat} and your /var/cache/yum/ folder was huge then removal of whatever is the equivalent in debian would be a start.
    – ron
    Commented Apr 9 at 19:09

1 Answer 1

5
  • sudo journalctl --vacuum-size=300M reduces the logs to 300 MB
  • sudo logrotate /etc/logrotate.conf compresses or (?) deletes system logs
  • sudo apt-get autoremove removes software that are only dependencies to packages you removed earlier and don't need anymore
  • sudo apt-get clean this is nearly the same as sudo rm -rf /var/cache/apt/archives/* and deletes cached downloaded packages for installation. Running this during some installations could be a problem.
  • Deleting files from the trashbin trash:/ and checking if there's any large files that could be deleted in /tmp: find /tmp -type f -size +50M -exec du -h {} \; | sort -n
  • Identifying largest files with a command like sudo find / -mount -type f -size +100M -exec du -h {} \; | sort -n (a few more are here and here) or with a GUI like gdmap (Graphical Disk Map) and then either moving/deleting them or creating symbolic links.
    • For example, to create a symbolic link for the relatively large daily.cld file of ClamTk one could run sudo mv /var/lib/clamav/daily.cld /home/username/Software/daily.cld then sudo ln -s "/home/username/Software/daily.cld" "/var/lib/clamav/daily.cld" so this also works for files used by software that expect the file to be in a specific location. Directories where one can commonly find large files include /opt/.
  • Another thing one can do is deduplicating things media by replacing duplicates with symlinks but I don't know of a command or tool that does that (or helps you do that)
  • The GUI BleachBit may have some additional ways

If, like me, you had your system crash or not be able to run the desktop environment (such as KDE Plasma) because of too little disk space, you could run the CLI commands from a TTY to delete files from there to free up enough disk space. You can switch to a virtual terminal (TTY) and back with Ctrl+Alt+F1 (or F2,F3,..). Once you have freed up enough disk space you can switch back using these shortcuts and restart the desktop environment (for KDE that's kstart5 plasmashell).


If you have this problem because you need more disk space for a distro upgrade, I suggested a stepwise upgrade as a solution that would make this redundant and avoid upgrade interruptions due to No disk space left. There devs brought up some alternatives:

  • Running the command with the cache directory elsewhere, for example: apt upgrade -o dir::cache::archives=/media/apt-archives
  • untested: while sudo apt -s upgrade | grep '^Inst' | head -1 | awk '{print $2}' | xargs apt install; do sudo apt clean; done ("Use head -10 or whatever fits for more/less packages")

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .