Очистка linux сервера от мусора

How do I free up disk space?

My Ubuntu cloud server has left only 900MB of disk space. I’ll just empty the directory /tmp and wondering if there is any other location to clean up.

18 Answers 18

To delete downloaded packages (.deb) already installed (and no longer needed)

To remove all stored archives in your cache for packages that can not be downloaded anymore (thus packages that are no longer in the repository or that have a newer version in the repository).

To remove unnecessary packages (After uninstalling an app there could be packages you don’t need anymore)

To delete old kernel versions

sudo apt-get remove --purge linux-image-X.X.XX-XX-generic 

If you don’t know which kernel version to remove

dpkg --get-selections | grep linux-image 

Running clean freed up quite a bit of space. Immediately after, I ran autoclean and my free space went down by 45MB. Running clean again released this extra space.

I removed all the linux image listed by dpkg —get-selections | grep linux-image which caused me a boot error — the ubuntu disappeared from grub boot menu — this answer fixed the problem — try not remove the latest image

Ok, this has already been answered 100 times (& in this thread also), but I find it really strange to be upvoted 160 times, because: sudo apt-get clean It will -simply- remove the packages all the local copy of the packages that you may have downloaded when doing an installation +upgrade. This will almost empty the /var/cache/apt/archives directory. . So the next time you run sudo apt-get update it will re-download everything (already there). Just a heads-up. )

 sudo apt autoremove sudo apt autoclean 

see list of all installed packages, sorted by size. If you see something big and don’t use it — uninstall it

 dpkg-query -W --showformat='$ $\n' | sort -nr | less 
 sudo apt install localepurge 
 find / -size +50000 -exec ls -lahg <> \; 
 sudo journalctl --vacuum-size 10M 

To find big files I suggest ncdu , which provides a fast way to see what directories are using your disk space

After running ` sudo journalctl —vacuum-size 10M` I am getting Warning: journal has been rotated since unit was started, output may be incomplete. message , how could I fix it?

Читайте также:  Запустить файл через командную строку linux

That can clean out a lot of guff (old kernels, etc) that have been replaced. You can do a similar thing in Synaptic (load it up and select the status button and then the Auto-removeable option).

will it not affect running applications like if it removes any necessary package on which any application depends?.

No. Autoremove looks for orphaned packages, that is to say packages that you didn’t explicitly install yourself (ones marked auto) and that have no dependencies. If you use aptitude instead of apt-get , it can clean up as you go but it’s quite common for older installations to collect a raft of installed kernels as security updates come out.

Typo in my last comment. I meant to say that orphaned packages are ones that aren’t depended on, not ones that «have no dependencies». They may well have dependencies and if they were only there for that orphaned package, they’ll be removed too. Some times (with really deep dependency trees) it can take a couple of autoremoves to clean up.

While the above command is certainly useful, it will not, as stated, remove old kernels. That has to be done either manually or with additional tools like Ubuntu Tweak.

@nyarlathotep It will remove kernel header files, which at first glance may make one think it’s removing the old kernels — the old kernels remain, however (try dpkg —get-selections | grep linux-image ).

I just freed up almost 2 gigs by removing old kernels and header files:

to check your current version, then

dpkg -l linux-image-* linux-headers-* 

to see all the old kernels and header files, then

sudo apt-get remove linux-image- linux-headers-

the apt-get remove command supports wildcards, so you can do apt-get remove linux-image 3.0.* linux-headers-3.0.* for example, to get rid of many at once.

Make sure you don’t kill remove current kernel of course! And maybe keep one or two old version, just in case. but not 10 or 20!

That bit about wildcards ? Before making use of it I would double-check that because I tried it and I got more than I wanted. It’s possible (perhaps even likely) that I stuffed up in some way but I don’t know how and yet I lost more headers than I wanted .

Do not forget to Empty Trash.

screenshot

rm -r ~/.local/share/Trash/info/ && rm -r ~/.local/share/Trash/files/ 

Or just trash-empty using trash-cli package.

rm.sh: ~/.local/share/Trash/info/: No such file or directory can I directly do command rm -rf ~/.local/share/Trash/* ?

Notice that with «shell-safe» you won’t actually delete any file, as they state at github site «Using safe-rm, the files or directories you choose to remove will move to $HOME/.Trash instead of simply deleting them».

Uninstall large packages that you don’t use

Some packages can be quite large. A convenient way of finding these is to use dpigs . It’s not installed by default but can be found in debian-goodies (GitHub project)

sudo apt-get install debian-goodies 
$ dpigs 419576 texlive-latex-extra-doc 204112 nvidia-319 175463 google-chrome-stable 141058 linux-image-extra-3.11.0-15-generic 113173 libreoffice-core 104822 valgrind 102322 qt4-doc 93337 blender 91105 texlive-pstricks-doc 90517 libboost1.53-dev 
-n, --lines=N Display the N largest packages on the system (default 10). -s, --status=status-file Use status-file instead of the default dpkg status file. -S, --source Display the largest source packages of binary packages installed on the system. -H, --human-readable Display package sizes in human-readable format (like ls -lh or du -h) -h, --help Display this message. 

I really recommend you the program BleachBit, which cleans everything on Ubuntu. Install it using the following command:

sudo apt install bleachbit 

Would be nice as you can share more details at which cleans everything on Ubuntu > A great graphical GUI tool to fit all needs askubuntu.com/a/18459/349837

Читайте также:  Создать папку горячие клавиши linux

Remove all old kernel versions automatically

Attention: If you’ve just upgraded the kernel, reboot before deleting the older versions!

Remember to check which kernel you are using type:

sudo apt-get remove --purge $(dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/3/!d') 

read that thread to be safe not to remove needed kernels with this command!

If you run into problems, use this script instead: https://askubuntu.com/a/1409370/34298

Check for large numbers of log files too:

Or as rubo77 points out in commends, you could use the NCurses disk usage tool:

Check out logrotate for how to purge older logs; though under systemd logs are handled by journald and so you’ll need to look at the journald conf files.

Cleaner script

This script will execute the biggest chunks on the console:

  • Clean apt cache
  • Remove config files left from uninstalled .deb packages (happens if you don’t use the —purge switch with apt-get )
  • Remove every kernel except the one you are using
  • Empty the trashes of every user(including root)

create a file with this content and give it executable rights:

#!/bin/bash # Adapted from 71529-ubucleaner.sh - https://web.archive.org/web/20151209182520/http://opendesktop.org/CONTENT/content-files/71529-ubucleaner.sh OLDCONF=$(dpkg -l|grep "^rc"|awk '') CURKERNEL=$(uname -r|sed 's/-*[a-z]//g'|sed 's/-386//g') LINUXPKG="linux-(image|headers|ubuntu-modules|restricted-modules)" METALINUXPKG="linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)" OLDKERNELS=$(dpkg -l|awk ''|grep -E $LINUXPKG |grep -vE $METALINUXPKG|grep -v $CURKERNEL) YELLOW="\033[1;33m"; RED="\033[0;31m"; ENDCOLOR="\033[0m" if [ $USER != root ]; then echo -e $RED"Error: must be root! Exiting. "$ENDCOLOR exit 0 fi echo -e $YELLOW"Cleaning apt . "$ENDCOLOR aptitude clean apt-get autoremove apt-get autoclean echo -e $YELLOW"Those packages were uninstalled without --purge:"$ENDCOLOR echo $OLDCONF #apt-get purge "$OLDCONF" # fixes the error in the original script for PKGNAME in $OLDCONF ; do # a better way to handle errors echo -e $YELLOW"Purge package $PKGNAME" apt-cache show "$PKGNAME"|grep Description: -A3 apt-get -y purge "$PKGNAME" done echo -e $YELLOW"Removing old kernels. "$ENDCOLOR echo current kernel you are using: uname -a aptitude purge $OLDKERNELS echo -e $YELLOW"Emptying every trashes. "$ENDCOLOR rm -rf /home/*/.local/share/Trash/*/** &> /dev/null rm -rf /root/.local/share/Trash/*/** &> /dev/null echo -e $YELLOW"Script Finished!"$ENDCOLOR 

Find large folders and packages

Some tools that will help you find large folders and packages:

sudo apt install ncdu debian-goodies deborphan sudo ncdu -xr / # lists all folders by size on the console (like the gui `baobab`) dpigs -H # shows large packages that you don't use man deborphan # finds packages that have no packages depending on them deborphan --guess-all --libdevel | xargs apt-get -s purge 

Localepurge

Use localepurge to uninstall unused languages in your system:

sudo apt install localepurge sudo localepurge 

Remove old snapd images

LANG=c snap list --all | awk '/disabled/' | \ while read snapname revision; do \ snap remove "$snapname" --revision="$revision"; \ done 

Bleachbit

A great graphical GUI tool to fit all needs:

sudo apt install bleachbit 

More info about Bleachbit here.

Читайте также:  Клиент rdp для линукс

Clear pythons pip cache

pip cache purge sudo pip cache purge 

Check your temp and cache folder

ncdu /var/tmp ncdu /var/cache 

Remove manpages and documentation

Additionally you can remove manpages and documentation as described in the Ubuntu Wiki:

Create a file /etc/dpkg/dpkg.cfg.d/01_nodoc which specifies the desired filters. Example:

path-exclude /usr/share/doc/* # if we need to keep copyright files for legal reasons: # path-include /usr/share/doc/*/copyright path-exclude /usr/share/man/* path-exclude /usr/share/groff/* path-exclude /usr/share/info/* # lintian stuff is small, but really unnecessary path-exclude /usr/share/lintian/* path-exclude /usr/share/linda/* 

Remove the same set of files and directories in the project-config’s postinst. Example:

echo "Removing documentation. " # if we need to keep copyright files for legal reasons: # find /usr/share/doc -depth -type f ! -name copyright | xargs rm || true # else: find /usr/share/doc -depth -type f | xargs rm || true rm -rf /usr/share/man/* /usr/share/groff/* /usr/share/info/* /usr/share/lintian/* /usr/share/linda/* /var/cache/man/* 

Источник

Чистим Ubuntu Server от мусора

Запись 0 0 * * * означает запуск команды ежедневно в 00:00 по времени на сервере.
В самом файле есть подсказка по настройке тайминга запуска, поэтому вы можете настроить запуск необходимых команд в любое время.

# Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr . # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed

Ошибка 403 CSRF Protection при входе в админку Django 4.*

При попытке входа в админку Django 4.* возникает 403-я ошибка CSRF Protection. Согласно списку изменений CSRF_TRUSTE…

Как обновить все пакеты в node.js?

Установите npm-check-updates: npm i -g npm-check-updates Далее будут доступны команды: ncu -u npm insta…

Проблемы с file-loader в Webpack 5

file-loader не работает в Webpack 5, замените его на: < test: /\.(gif|png|jpe?g|svg)$/i, type: 'asset/re…

Как запустить, перезапустить, остановить, узнать статус Nginx в Ubuntu?

Systemctl: start\restart\stop\status sudo systemctl restart nginx sudo systemctl start nginx sudo systemctl sto…

Выводим Inline формы в админке Django в зависимости от группы в которой находится пользователь

Начиная с версии Django 3.* доступен метод get_inlines. Допустим мы хотим показать Inline форму если пользователь на…

Источник

Оцените статью
Adblock
detector