- How to clean /var/cache?
- 6 Answers 6
- What files can be deleted if there is not enough disk space on Linux
- 1. Delete temporary files
- 2. Removing cache files
- 3. Deleting logs
- 4. Empty the trash bin
- 5. Removing unnecessary kernel header source files
- 6. Removing orphaned packages
- 7. Files in the /lost+found directory
- 8. Cleaning up PHP sessions
- (BONUS) 9. Analyze Docker Files
- Conclusion
- Related articles:
- Как почистить /var/cache?
- 6 ответов
- Is it safe to manually delete the /var/cache/apt content?
- 4 Answers 4
How to clean /var/cache?
The space is used by /var/cache/polipo (2.7G). How can I clean this up safely?
I tried restarts=>didn’t work
Used bleachbit=>the space is not detected in the cleanup preview PS: I did rm -rf youtube inside /var/cache/polipo and it freed up 2G space. Dunno if it was safe though
6 Answers 6
sudo apt-get autoclean sudo apt-get autoremove
All these were already done. The problem is in /var/cache. I want to know how to clean /var/cache safely.
Polipo, a web caching program may store a lot of data in an on-disk cache.
One way to clear this up is to issue the command sudo polipo -x — this will cause polipo to clear the local disk cache.
This is the ONLY right answer to this question (regarding polipo)! Why the hell does it not already have enough votes to make that clear.
The most powerful of all commands to clean the cache for command line users is of course
Which will also delete all the cached files.
I don’t know what this command did but it didn’t clear /var/cache, space is nearly double after I ran it!
Try cleaning ubuntu unnecesarry files using bleachbit. It is a tool that will help you clean your cache, temp files, cookies and it has other features also.
sudo apt-get install bleachbit
It sounds so obvious, and yet chances are you haven’t done this.
By default Ubuntu keeps every update it downloads and installs in a cache on your disk, just in case you ever need it again.
This is useful if you regularly add and remove apps, find yourself needing to reconfigure/reinstall a specific package, or simply have a poor connection.
But the flip side is that the apt package cache can quickly swell to several hundred MBs. This command tells you how big your apt cache is:
du -sh /var/cache/apt/archives
To clean the apt cache on Ubuntu simply run the following command.
The apt clean command removes ALL packages kept in the apt cache, regardless of age or need. If you’re on a slow, capped or intermittent connection you may want to consider skipping this step.
What files can be deleted if there is not enough disk space on Linux
That is, there are really critical situations – in these conditions, many programs and services cease to work normally. Therefore, the task becomes the following: immediately free up disk space at any cost so that you can continue to maintain the system and go to the second stage – search for directories and folders that led to this problem due to the fact that they began to take up too much space.
I will warn you in advance: the following commands, although basically delete useless files, after their execution you may need actions such as:
- restarting services for their normal operation (so that they recreate log files, caches, lock files)
- various logs and files from the recycle bin may be lost, which although most users do not need them, in some conditions you may want to keep them (for example, it is important for you to investigate the log files, as they may contain the cause of the problem).
This means that DO NOT mindlessly copy-paste commands – read he explanations to them and evaluate how painless they are for your situation.
1. Delete temporary files
The files in the /tmp/ folder will be deleted anyway the next time the system is rebooted. That is, on the one hand, they can be removed quite painlessly:
BUT: the work of programs that are currently running and which have saved some data in the /tmp/ folder may be disrupted.
2. Removing cache files
There are many subdirectories in the /var/cache/ directory that can be deleted almost painlessly (data will not be lost, and programs will create new cache files). This directory is of particular interest because on some systems caches grow into gigabytes and tens of gigabytes. Sometimes, finding the problem directory in /var/cache/ can finally solve the situation with a lack of disk space.
sudo rm -rf /var/cache/fontconfig/
To remove the installation package cache (on Debian, Linux Mint, Ubuntu, Kali Linux and their derivatives):
To remove the installation package cache (on Arch Linux, BlackArch and their derivatives):
sudo rm -rf /var/cache/pacman/
Removing the manual page cache:
You can continue to search for large caches applicable to the software installed on your system. For example, it could be the caches of a web server, proxy server, etc.
3. Deleting logs
You can delete almost all files in this (/var/log/) folder, but try to keep the folder structure, since some applications, after deleting the folder here, are not able to recreate it…
Web server logs can grow too much on web servers.
To delete Apache logs on Debian, Linux Mint, Ubuntu, Kali Linux and their derivatives:
To delete Apache logs on Arch Linux, BlackArch and their derivatives:
For the server to start creating new log files and writing to them, you need to restart the web server service.
Depending on the intensity of use of the system, accumulated logs can occupy gigabytes. Depending on the system, files can be named in different ways; more accurate analysis is recommended using the ncdu utility:
4. Empty the trash bin
This tip is more for desktop systems. Files that you deleted in the graphical interface of the desktop fall into the ~/.local/share/Trash/files/ folder, you can analyze them and delete them (second time) if you wish:
ncdu ~/.local/share/Trash/files/
5. Removing unnecessary kernel header source files
The following applies only to Debian, Linux Mint, Ubuntu, Kali Linux and their derivatives. Check the folder /usr/src/, there will be subfolders of the form linux-headers-, most of them can be deleted – leave only the one whose number corresponds to the current kernel of the system – usually this is the latest release number.
6. Removing orphaned packages
Orphaned packages are those packages (programs) that were installed as dependencies for other programs. But for various reasons, they are no longer needed: either the program that used them was removed, or for that program they ceased to be dependencies after updating the program.
On Debian, Linux Mint, Ubuntu, Kali Linux and their derivatives, you can remove unnecessary packages as follows:
For Debian and its derivatives, the previous command is completely safe.
In Arch Linux and derivatives, the list of orphaned packages can be seen as follows:
Before proceeding to their automatic removal, it is strongly recommended that you pay attention to this list!
To recursively remove orphans and their configuration files in Arch Linux and derivatives:
sudo pacman -Rns $(pacman -Qtdq)
If no orphaned packages were found, pacman will exit with an error: no targets specified (use -h for help). This is expected since pacman -Rns received no arguments.
7. Files in the /lost+found directory
Files that were found after checking the disk file system are saved in the /lost+found folder. Typically, such checks are performed after a sudden reboot of the system or in case of signs of disk problems.
Found files are usually damaged. Their goal is to save data that, if errors were fixed on the file system, would be completely lost.
The /lost+found folder may be empty (if there were no problems with the disk). If there are files there, then you can review them and, if desired, delete them.
8. Cleaning up PHP sessions
Sometimes web applications can create countless sessions due to a bug. Check the directory /var/lib/php/sessions/ for too many files.
(BONUS) 9. Analyze Docker Files
Do not madly delete Docker files. I give an example of this directory only for the reason that it attracted my attention because of its simply phantasmagorical size – and this despite the fact that I do not actually use Docker – I tried several times to see what it was.
The largest folder is /var/lib/docker/overlay2/. To analyze the consumed disk space:
Conclusion
So, we examined what files can be deleted from Linux with virtually no loss of information. In addition to the above directories, which can be cleaned both on a remote system with a web server and on a home computer, users with a graphical desktop should pay attention to such directories as:
They DO NOT need to be removed, but worth analyzing. For example, you can find out that the web browser on your computer has a cache of several gigabytes and that you can free them (it is recommended to do it using the web browser, rather than deleting files directly).
If I missed some directories with files that can be deleted painlessly, then write them in the comments!
Related articles:
Как почистить /var/cache?
Пространство используется /var/cache/polipo (2.7G). Как я могу очистить это безопасно?
Я пытался перезагрузки => не работает
Используется bleachbit=> пространство не обнаружено в предварительном просмотре очистки
PS: я сделал rm -rf youtube внутри / var / cache / polipo, и это освободило пространство 2G. Не знаю, если это было безопасно, хотя
6 ответов
Polipo, программа веб-кэширования, может хранить много данных в кеше на диске.
Один из способов прояснить это — выполнить команду sudo polipo -x — это заставит polipo очистить кэш локального диска.
sudo apt-get autoclean sudo apt-get autoremove
Запустите bleachbit от имени пользователя root: на диске нет места; sudo apt-get clean не работает
Самая мощная из всех команд для очистки кэша для пользователей командной строки, конечно,
Который также удалит все кэшированные файлы.
Это звучит так очевидно, и все же есть вероятность, что вы этого не сделали.
По умолчанию Ubuntu хранит каждое загружаемое обновление и устанавливает его в кэш на вашем диске, на случай, если вам когда-нибудь понадобится это снова.
Это полезно, если вы регулярно добавляете и удаляете приложения, вам необходимо перенастроить / переустановить конкретный пакет или просто иметь плохое соединение.
Но с другой стороны, кеш пакетов apt может быстро увеличиться до нескольких сотен МБ. Эта команда сообщает вам, насколько велик ваш apt-кеш:
du -sh / var / cache / apt / archives
Чтобы очистить кэш apt в Ubuntu, просто выполните следующую команду.
Команда apt clean удаляет ВСЕ пакеты, хранящиеся в кэше apt, независимо от возраста или необходимости. Если у вас медленное, ограниченное или прерывистое соединение, вы можете пропустить этот шаг.
Is it safe to manually delete the /var/cache/apt content?
On an embedded system with a very limited disk space I have the folder /var/cache/apt full with some 700MB of srcpkgcache.bin.* and a couple of large *.bin files. Performing sudo apt-get clean did not make a visible difference. Is it safe to manually delete these *.bin* files?
As of Ubuntu 14.04 it is perfectly safe to remove the *.bin files in said folder — assuming no apt-related process is currently running. The next apt-get update will regenerate the *.bin files. This question is decidedly not about the files in /var/cache/apt/archives , but the files /var/cache/apt/*.bin . Big difference. The former can be cleaned by issuing apt-get clean , the latter has to be manually removed. Clearly those voting to close the question have not read the question properly. Unfortunately I cannot vote to reopen after awarding some of my rep in bounties.
This is not a duplicate. The linked answer is about the subdirectory archives within /var/cache/apt/ , this one is about the *.bin* files.
4 Answers 4
Not really. Those files help your system determine what is available and what isn’t. Emptying that directory will result in a broken apt-get system. Here are a couple of tips.
First, auto clean
to the end of /etc/apt/apt.conf . It will make apt and dpkg processes take longer, but will make it so your cache directory is always clean.
Next, Remove archives
Start by removing and disabling all source archives (that your not using). On an embedded system you likely don’t need them. Next remove all the archives that are not in use. You can run apt-cache policy to figure out what repo a package is coming from if your not sure.
More Removal of archives
Some PPAs are horrid about having huge number of packages in them when you only need 1 or 2. Try disabling those PPAs and just installing the deb files manually. You save space in those cases, but you loose auto update. Keep in mind that dpkg will handle dependencies, so you can still install thing-with-tons-of-deps.deb then run apt-get -f install to fetch the dependencies.
Totally Extreme Answer 1
Because were talking about an embedded system, 90% of the main repos won’t do you any good. To handel this you could run your own apt-get repo server See this link. It’s not easy, and it’s a PIA for just one machine. But if you have several of these machines it’s totally worth it. (You apt repo server can host just a subset of packages that you actually use. You don’t need to mirror the whole thing)
Totally Extreme Answer 2
If space is really that large of an issue, then you can disable apt all together and revert to manually installing via dpkg. I have had to do this on several embedded systems. It works, but it’s an admin nightmare.