Cleaning the system with commands

Hi all, until now Ubuntu-Tweak used for cleaning the system, but as you know is no longer supported. The other day I found a blog where by commands perform that operation.
I leave here all information:

Uninstall useless packages in ubuntu

Remove the kernels that are no longer used

When there is a new kernel and upgrade, installed the new but the old man is installed. This is so that if the new kernel something does not work, you can enter the old (selecting the previous kernel in the grub menu). But it may be we begin to accumulate a considerable amount of kernels that do not serve us all. To remove the kernels that you no longer use, we must execute the following lines:

CURKERNEL=$(uname -r | sed 's/-*[az]//g' | sed 's/-386//g')

OLDKERNELS=$(dpkg -l | awk '{print $2}' | grep -E "linux-(image|headers|ubuntu-modules|restricted-modules)" | grep -ve "linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)" | grep -v $CURKERNEL)

sudo apt purge $OLDKERNELS

The explanation of what makes that: The first thing you need to know is that kernel need. To do uname -r | sed 's / - * [az] // g' | sed 's / -386 // g' gives the kernel version. Then we need to know that kernels installed. The dpkg -l command shows us what we have installed. The command awk '{print $2}' catches of each packet the name of this. The order grep -E "linux- (image | headers | ubuntu-modules | restricted-modules)" leaves only the packets that are images, headers, kernel modules. The command grep -ve "linux- (image | headers | restricted-modules) - (generic | i386 | server | common | rt | xen) leaves only the packets of images, headers and modules that correspond to specific versions And finally. -v grep command $CURKERNEL leaves packages that are not of the latest version we have (which we have had to keep on variable $CURKERNEL). once we have and ready to remove, remove them with sudo aptitude purge .
Remove packages that no longer serve

Autoremove: When you install a program might bookstores and other programs which also depends on installed. But when we uninstalled the program it is likely that these libraries remain installed and are no longer used. But we will uninstall executing the following command:

sudo apt-get autoremove

Autoclean: What it does is remove packages incomplete downloads or canceled for some reason. We’ll have to run the following command:

sudo apt-get autoclean

Clearing the cache of aptitude

When we install programs from the repositories, the first thing it does is lower the installers then install them . But after installation, these files remain on your computer. These files can be deleted as needed if he again will drop again. To delete these files have to run the following command:

sudo apt-get clean

Deleting files from packages that are not already installed

Although desinstalemos programs, some files may stay program (eg configuration files, …). To delete these files have to execute the following lines:

OLDCONF=$(dpkg -l | grep '^rc' | awk '{print $2}')

sudo apt purge $OLDCONF

The explanation of what that does: the dpkg -l command lists the installed packages, starting every package we can see certain codes that indicate the status of packages, for example: - “ii” = installed - “rc” = Removed, but with configuration files on the system’s rc packages they are those that interest us and we have to clean this information. The grep command “^ rc” what it does is leave only the lines that start with “rc”. Then awk '{print $2}' does is show the second parameter of these lines, which is just the package name. Once we have all the packages that have left configuration files on the system, the purge will remove with aptitude.
Emptying the bins

When you delete a file, it is moved to the recycle bin. In this way we can recover in case of error. But if we leave them there forever, we may ocumen much space. So should periodically emptied:

rm -rf /home/$USER/.local/share/Trash/*/
rm -rf /root/.local/share/Trash/*/

The first command removes the bins of all users. The second line deletes the trash the root.

2 Likes

A couple of links for the English speakers as @Juanjo’s link is in Spanish:

http://www.ubuntugeek.com/cleaning-up-a-ubuntu-gnulinux-system-updated-with-ubuntu-14-10-and-more-tools-added.html

http://www.ubuntugeek.com/cleaning-up-all-unnecessary-junk-files-in-ubuntu.html

Don’t forget about “Bleachbit” too!:

http://www.howtogeek.com/116971/7-tips-to-get-the-most-out-of-bleachbit-a-ccleaner-for-linux/

1 Like

Bleachbit is in the Software Boutique for a reason :wink:

3 Likes

Hello, I know, but does not have an option to delete old kernel.
The interesting thing is to have an application as it was ubuntu-tweak, that with a few simple clicks, done. Facilitate the work of cleaning the system novice, like myself. :smile:

Regards

Juanjo

1 Like

I'm +1 for BleachBit, plus it offers the ability to preview files before deletion, and specify custom folders to delete (like Steam's httpcache folder) :clear:

For removing old kernels, I use this one command:

1 Like

There is another cli application available that handles removing old kernels:
http://manpages.ubuntu.com/manpages/xenial/en/man1/purge-old-kernels.1.html

I think it’s nice since it removes all the kernel files and lets you specify how many older versions you want to keep.

1 Like

The “autoremove” command will remove old kernels, so yes, BleachBit will remove old kernels.