You Ads Here!

Simple Bash Script To Keep Your Ubuntu Box Clean

Ubuntu LogoThe Ubucleaner is a simple bash script that help you to keep your Ubuntu box clean. This script will help you to run 4 task in one single command. The Script will do automatically and our job is answer the question that appear during script running. Or you could modify the script to fit with your environment.

The list on the below is the 4 task that will perform by this script, Please read carefully.

Ubucleaner Features

- Clean apt cache
- Remove config files left from uninstalled .deb packages(it 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)

It uses apt and the kernel removing thing searches for ubuntu-only packages, so it can’t work on non-debian system and the result is undetermined for other debian-based system, but you can still use the other features of the script (you’ll just have to comment the parts you don’t want).

The script assumes that you are using the text-based Aptitude application, rather than apt-get and dpkg. If you are not using Aptitude, you should also replace the reference to aptitude clean with apt-get clean and the reference to aptitude purge to dpkg–purge.This can be done done by editing the following script.

First you need to download the script from here or using the following command

wget http://simplyeko.com/uploads/ubucleaner.sh

Now you should have ubucleaner.sh file you need to give execute permissions using the following command

chmod +x ubucleaner.sh

Run the script using the following command

prast@simplyeko:~$ ./ubucleaner.sh
Error: must be root
Exiting…
prast@simplyeko:~$ sudo ./ubucleaner.sh
[sudo] password for prast:
Cleaning apt cache…
Reading package lists… Done
Building dependency tree
Reading state information… Done
Reading extended state information
Initializing package states… Done
Building tag database… Done
Removing old config files…
Reading package lists… Done
Building dependency tree
Reading state information… Done
Reading extended state information
Initializing package states… Done
Building tag database… Done
No packages will be installed, upgraded, or removed.
0 packages upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 0B will be used.
Reading package lists… Done
Building dependency tree
Reading state information… Done
Reading extended state information
Initializing package states… Done
Building tag database… Done
Removing old kernels…
Reading package lists… Done
Building dependency tree
Reading state information… Done
Reading extended state information
Initializing package states… Done
Building tag database… Done
The following packages will be REMOVED:
linux-headers-2.6.24-16{p} linux-headers-2.6.24-16-generic{p}
linux-image-2.6.24-16-generic{p}
linux-restricted-modules-2.6.24-16-generic{p}
linux-ubuntu-modules-2.6.24-16-generic{p}
0 packages upgraded, 0 newly installed, 5 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 193MB will be freed.
Do you want to continue? [Y/n/?]
Writing extended state information… Done
(Reading database … 139532 files and directories currently installed.)
Removing linux-headers-2.6.24-16-generic …
Removing linux-headers-2.6.24-16 …
Removing linux-restricted-modules-2.6.24-16-generic …
Purging configuration files for linux-restricted-modules-2.6.24-16-generic …
Removing linux-ubuntu-modules-2.6.24-16-generic …
update-initramfs: Generating /boot/initrd.img-2.6.24-16-generic
Purging configuration files for linux-ubuntu-modules-2.6.24-16-generic …
Removing linux-image-2.6.24-16-generic …
Running postrm hook script /sbin/update-grub.
Searching for GRUB installation directory … found: /boot/grub
Searching for default file … found: /boot/grub/default
Testing for an existing GRUB menu.lst file … found: /boot/grub/menu.lst
Searching for splash image … found: (hd0,0)/boot/grub/splashimages/medine_moon_right_below.xpm.gz

Found kernel: /boot/vmlinuz-2.6.24-22-generic
Found kernel: /boot/memtest86+.bin
Replacing config file /var/run/grub/menu.lst with new version
Updating /boot/grub/menu.lst … done

The link /vmlinuz.old is a damaged link
Removing symbolic link vmlinuz.old
you may need to re-run your boot loader[grub]
The link /initrd.img.old is a damaged link
Removing symbolic link initrd.img.old
you may need to re-run your boot loader[grub]
Purging configuration files for linux-image-2.6.24-16-generic …
Running postrm hook script /sbin/update-grub.
Searching for GRUB installation directory … found: /boot/grub
Searching for default file … found: /boot/grub/default
Testing for an existing GRUB menu.lst file … found: /boot/grub/menu.lst
Searching for splash image … found: (hd0,0)/boot/grub/splashimages/medine_moon_right_below.xpm.gz

Found kernel: /boot/vmlinuz-2.6.24-22-generic
Found kernel: /boot/memtest86+.bin
Updating /boot/grub/menu.lst … done

Reading package lists… Done
Building dependency tree
Reading state information… Done
Reading extended state information
Initializing package states… Done
Writing extended state information… Done
Building tag database… Done
Emptying every trashes…
Script Finished!

afterward you have clean Ubuntu system and of course freed some space on HDD.

  • 5 Things to Do Before Upgrade to Ubuntu Linux Intrepid

  • Google For Hackers

  • Popularity: 12% [?]



    Are you satisfied with this blog?
    Why not subscribe our RSS Feed? you will always get the latest post.


    4 Comments


    1. As an alternative please consider this for package and cache cleaner

      Ubuntu Tweak

      1

    2. Have just tried it out on my laptop and it works sweet as. Will be doing the same to my network file server later on once the backup is complete.

      2
    3. Eko Prasetyo

      # Silo
      thanks for the tip

      # AC installer
      hopefully it works also on server.

      3

    4. nice tips for clean, purge, and Emptying every trashes.i will try it

      cengeks last blog post..Lampu Kota di Simpang Seraya

      4

    Leave A Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>