2

The thing is /home has only used 11GB whereas /var uses 14GB, /temp 11GB and /swapfile 2.4GB

Can I safely do sudo rm * in the last three directories?

Contents from sudo du /var | sort -n | tail -20

679376  /var/snap/microk8s/common/run
683324  /var/lib/docker/overlay2/3ecccaf38f1f0837b174563be1ce108c862264359047750fd3daceae9a015182/diff/usr
683424  /var/lib/docker/overlay2/2313ac4c63c3915860ed097576334e5167ca94569ebfafd585f30d456dd1e33b/diff/usr
735748  /var/lib/docker/overlay2/3ecccaf38f1f0837b174563be1ce108c862264359047750fd3daceae9a015182/diff
735756  /var/lib/docker/overlay2/3ecccaf38f1f0837b174563be1ce108c862264359047750fd3daceae9a015182
735840  /var/lib/docker/overlay2/2313ac4c63c3915860ed097576334e5167ca94569ebfafd585f30d456dd1e33b/diff
735848  /var/lib/docker/overlay2/2313ac4c63c3915860ed097576334e5167ca94569ebfafd585f30d456dd1e33b
879292  /var/snap/microk8s/common/var/lib/containerd
954104  /var/snap/microk8s/common/var/lib
1161476 /var/snap/microk8s/common/var
1451924 /var/lib/docker/volumes
1840856 /var/snap/microk8s/common
1878948 /var/snap/microk8s
1879156 /var/snap
2923700 /var/lib/snapd/snaps
3967480 /var/lib/snapd
4971824 /var/lib/docker/overlay2
6437580 /var/lib/docker
10813292    /var/lib
12804788    /var
Eduardo Trápani
  • 12,032
  • 1
  • 18
  • 35
Josh
  • 121
  • 3
  • 1
    Generally there should be not a problem to delete temp, but you should give us more information. What OS are you iusing? How is partitioned your disk? etc. Do you know which programs did that directories? – nobody Jul 20 '20 at 18:11
  • 2
    You've got `docker` images and various `snap` applications. It's up to you whether to delete them or not but deleting them *directly* would most likely be a bad idea. Use the appropriate commands to clean them. – Artem S. Tashkinov Jul 20 '20 at 18:40

2 Answers2

1

The info you've given is all mixed up.

I presume you're talking about

/var
/tmp
/swapfile
  • You absolutely cannot rm -rf /var - you system may become unbootable.

  • You may safely delete everything from /tmp and /var/tmp.

  • Deleting /swapfile without first removing this entry from /etc/fstab is not advisable. Also, if you're low on RAM (4GB or less) /swapfile might be crucial for proper system functioning.

  • If you have a normal home PC /var shouldn't occupy 14GB.

    Please post the output of sudo du /var | sort -n | tail -20

Artem S. Tashkinov
  • 26,392
  • 4
  • 33
  • 64
  • swapfile never has a . in front of it. – Rinzwind Jul 20 '20 at 18:21
  • My bad, yes those are the directories that I'm talking about, I updated my post with the output requested – Josh Jul 20 '20 at 18:24
  • @Rinzwind you can name a swap file anything you want except except NUL ('\0') and '/' – Artem S. Tashkinov Jul 20 '20 at 18:35
  • Just a point of clarity, you discuss NOT removing something as `rm -rf` but then say you can delete other things. A careless reader might assume you mean you can `rm -rf /tmp /var/tmp` which could leave your system inoperable. Further deleting temp files blindly can be dangerous if there are things in progress which might use them. Better to delete "old" files only and ensure thing like a system upgrade is running at the time. – Philip Couling Jul 20 '20 at 18:52
  • @ArtemS.Tashkinov, what names the common installers use might be a bit more relevant than that. I have `/swapfile` on my Xubuntu, and at least I can't _remember_ naming it that myself. And if we really go into it, of course you can use slashes in the swap file's name, just create some directories for it first. – ilkkachu Jul 20 '20 at 18:57
  • @PhilipCouling I haven't deleted /tmp, so it isn't safe? the files are not being deleted on reboot – Josh Jul 20 '20 at 19:02
  • @PhilipCouling for several releases now Fedora has had its `/tmp` in `tmpfs`, so I'm pretty sure deleting everything from /tmp is safe as long as you reboot afterwards. I have never implied `rm -rf` any of the above directories should be tried. – Artem S. Tashkinov Jul 20 '20 at 19:02
  • @ArtemS.Tashkinov I'm on Ubuntu 20.04, can I safely `rm -r /tmp`? (without forcing) or not adviced – Josh Jul 20 '20 at 19:09
  • @Josh please run `cd /tmp && sudo rm -rf * .*` instead – Artem S. Tashkinov Jul 20 '20 at 19:15
  • You missed my point. It is safe as long as nothing critical is actively using them. When you reboot, you are correct, because during a reboot nothing is doing anything at all. But blindly deleting everything in /tmp on an active system could have consiquences for those processes that were using them files there. Is it not obvious that deleting any file which is on active use could have unfortunet consiquences? – Philip Couling Jul 20 '20 at 19:19
  • We are not talking about a mission critical server or system. A reboot is fast and easy. I do miss your point, sorry. And you don't offer any advice as to how to safely remove the contents of /tmp either. ;-) – Artem S. Tashkinov Jul 20 '20 at 19:26
  • Josh, you must have a /tmp directory even if you empty it. *Most of the time* emptying it is relatively safe. But remember that some process wrote this files for a reason even if it forgot to clean them up once it was done. So if you have anything mission critical like a system upgrade running then wait until it's done. You might want to leave anything newer than 24 hours to be extra safe and just delete old files. – Philip Couling Jul 20 '20 at 19:26
  • /var could definitely become 14GB in size tough, because of the cache, docker containers and volumes, logs etc. It all depends on what the system is used for – aardbol Jul 23 '20 at 06:37
1

/var

I found a post which lists the contents of /var. Check it out here (go to the near bottom of the page to see what I mean): https://stackoverflow.com/questions/18514447/what-goes-in-var.

Judging from the contents, I wouldn't remove the data in it.

/tmp

The /tmp directory holds temporary files which may be needed in the session you are in. Since these files are needed by processes and programs, I wouldn't delete them, otherwise an error or breakage may occur.

It clears itself after every reboot, anyway. Something's wrong if it doesn't.

/swap

/swap (or a swap file) is the space in which inactive programs are put to allocate memory to active ones when a machine demands more memory than it can give. I don't know how intensely you use your computer, though, so I can't assess if you need it.

You may need /swap because:

  • You have a low amount of RAM, and you want to use what you have to the best of your ability.
  • You use programs that are intense on resources, and it may eat up your RAM
  • You use hibernation, and the contents of the RAM is written to swap
  • Programs can act weird and unnecessarily hog your RAM.

Source: https://itsfoss.com/swap-size/#:~:text=There%20are%20several%20reasons%20why,would%20exhaust%20the%20RAM%20soon.&text=If%20you%20use%20hibernation%2C%20then,written%20to%20the%20swap%20partition.

Now, you might have a lot of RAM. You probably wouldn't need any swap at all. But it's worth having at least a few gigabytes of swap just in case something happens which uses all your RAM.

To be on the safe side, I would recommend having at least some swap. I don't recommend deleting swap entirely.

Conclusion

I wouldn't delete any of these directories. Although it does seem like your /var and /tmp directories are quite filled. I don't really know what's up with that.

Hope it helps!

fr0stbyte
  • 96
  • 7
  • Thank you, I've rebooted and shutdown the system but /tmp is still filled, any idea what's going on? – Josh Jul 20 '20 at 19:01
  • When I say that it clears itself, I mean that unused `/tmp` files don't pile up. You may check after rebooting and see that it does have content in it. These files are most likely being used. Unless the amount of storage it takes is unusually high, I wouldn't worry. – fr0stbyte Jul 20 '20 at 19:04