3

I need to free up disk space on my linux server. I run the df command to check space ad see that I'm using up 100% of disk space.

myserver:/ # df /
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/nvme0n1p3  22775924 21448960    146960 100% /

I then run du -h --max-depth=1 and I see that root and var take up most space:

sudo du -h --max-depth=1
362M    ./run
2.8G    ./opt
16K     ./lost+found
0       ./sys
4.0K    ./selinux
1.6M    ./bin
542M    ./home
56M     ./boot
40M     ./etc
2.3G    ./var              <---- 2.3 G
40K     ./tmp
8.8M    ./lib64
845M    ./lib
4.0K    ./mnt
0       ./dev
0       ./proc
7.4M    ./sbin
2.2G    ./snap
20K     ./srv
2.5G    ./root             <--- 2.5 G
12G     ./usr
24G     .

I cd into root and check its contents as follows:

cd /root/
myserver:~ # sudo du -h --max-depth=1
70M     ./Downloads
4.0K    ./Public
8.0K    ./.keras
4.0K    ./Music
4.0K    ./bin
1.2M    ./Pictures
2.4G    ./.cache                <-- 2.4G
8.0K    ./.nv
9.1M    ./Videos
12K     ./.dbus
12K     ./.gnupg
64K     ./.java
38M     ./.mozilla
4.0K    ./Desktop
8.0K    ./.vnc
52K     ./.subversion
4.0K    ./Documents
596K    ./.config
4.0K    ./Templates
20K     ./snap
1020K   ./.local
2.5G    .

And see that .cache is very large at 2.4G so I cd in here and check its contents:

cd .cache/
myserver:~/.cache # ls -l
total 208
drwxr-xr-x 3 root root   4096 Aug  7 10:10 JetBrains
drwxr-xr-x 3 root root   4096 Sep 25 10:06 TeamViewer
drwx------ 2 root root   4096 Aug 11 06:57 dconf
drwxr-xr-x 2 root root   4096 Aug 11 05:23 gstreamer-1.0
drwx------ 2 root root   4096 Aug  6 15:49 libgweather
drwxr-xr-x 3 root root   4096 Aug  6 11:58 matplotlib
drwx------ 3 root root   4096 Aug  6 15:49 mozilla
drwx------ 5 root root   4096 Aug  3 06:21 pip
-rw-r--r-- 1 root root 165196 Aug  6 16:00 qt_compose_cache_little_endian_89282f2dafab46408a426c3d8ad33da7
drwxr-xr-x 2 root root   4096 Sep 25 10:07 qtshadercache
drwx------ 4 root root   4096 Sep  1 06:20 thumbnails
drwxr-xr-x 3 root root   4096 Aug  6 12:17 torch

Is it safe to delete the whole contents of this .cache folder without messing up anything?

Are these .cache contents used for anything after the packages have been installed??

Are there any 'better' ways to free up space?

2
  • We don't know what /root/.cache on your instance holds/may hold. Look inside, see if you can make sense of the files present and their timestamps ... even try to find the culprit.
    – tink
    Commented Sep 26, 2020 at 5:50
  • cd /root/.cache; du -sm *|sort -n ...
    – tink
    Commented Sep 26, 2020 at 5:53

2 Answers 2

4

You can delete all of .cache with no long term detrimental effects.

If your .cache is growing large, it might be better to look at the contents and determine what application is making it large and re-configure a bad acting application (rather than simply deleting .cache when it grows too large).

[ ... ]

For the most part you can delete most anything in your home directory. Programs or applications that require .cache (or other dot files such as .local) will re-create them.

Most of the time, at worst, you will lose custom configurations, but no real harm to the system.

I would not advise you start a habit of deleting things you do not understand in your home directory, back it up or use a test account. If in doubt, the safe thing would be to make a back up or move the file.

mv .cache .cache_backup

You can then restore from backup if needed.

Definitely do NOT start deleting things you do not understand outside of your home directory.

Source: askubuntu

Hope this was useful ;)

4
  • And how did you know that what's valid for Ubuntu was the same for OpenSUSE?
    – tink
    Commented Oct 2, 2020 at 20:39
  • It's not about Ubuntu, it's about Linux. Linux based systems use common folder configurations. For this specific case, take a look at $XDG_CACHE_HOME: superuser.com/a/1055476/1222905
    – MrJavy
    Commented Oct 3, 2020 at 5:39
  • Guess I must have been dreaming when I saw different distributions abuse varied directories in the LFS in varied ways over the last 25 years or so ...
    – tink
    Commented Oct 14, 2020 at 20:55
  • At least I hope it was a great dream! I do know some distros do not follow the 'main' route, however it does not change the answer for this specific question. Have a nice day ;)
    – MrJavy
    Commented Oct 15, 2020 at 8:19
0

One of the simple (not safe) ways to clean Linux, and make some free space, is using "BleachBit".

https://www.bleachbit.org/#google_vignette

You can clean your system drive for any user, even root (that make more free space).

Unselect cleaning Internet Browsers (you can clean them inside browsers), because you can destroy your add-on's (I had problems after destroy chromium locker, so how I manually found long-name strange folder in system to fix that).

You must log in to answer this question.

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