TransWikia.com

Is it safe to remove contents from var / swapfile / tmp?

Unix & Linux Asked on October 31, 2021

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

2 Answers

/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!

Answered by fr0stbyte on October 31, 2021

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

Answered by Artem S. Tashkinov on October 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP