March 3, 2010

Quick Tip - A Fast Update

I have been a Linux user for seven years, and have used it exclusively for five of those years now. The more I learn, the more interested I become. It is time I give something back, regardless how simple or complex an issue might be. One time saving trick I have been using for a long while now is using simple bash scripts to complete tasks. Running two different flavors of Linux has tought me a lot. I have been a Debian/Ubuntu user for a while, and recently started using CentOS. Both of these have the Linux kernel at heart, but work in different ways. I have two scripts I put together to make updating quick and easy. The first part is the script for the Debian based APT system, and the latter will be for the Red Hat based RPM system.


Okay, lets start. The first script will work for pretty much any Debian (.deb) based system, and it goes like this: Open a text editor of your choice - Vim, Emacs, gedit, etc, and enter in this string of commands. apt-get update apt-get update apt-get dist-upgrade -y apt-get autoremove -y apt-get autoclean

Now why did I do two apt-get update's instead of one. If you were to get an error, APT will tell you that you can fix the problem by running "apt-get update" again. To knock out that message from the start, I just go ahead and update twice, it can't hurt anything. I added in a "-y" to automatically answer yes to questions where a [Y/n] is required to continue on the process. Now save it as, I use so I can find this script among the others I have laying around on my hard drive. Be sure to have the .sh on the end, since this is a script. Now we are going to run it using a terminal like this. sudo bash

You have to have the sudo at the beginning of the command because an update is considered an administrative task, and running this bash script without sudo will lead you to many errors. You will see the script run line-by-line until it is finished. Here is the result of that very simple shell script you just ran:


On an RPM Linux system like Red Hat or CentOS, the script is a bit different, shorter number of commands, takes longer, but it accomplishes the same goal. You again want to open your text editor or choice and write these lines: yum clean all yum check update yum update -y yum clean all -y

Yum clean all -- dumps the current cache of information so you have a clean slate to start with. 

Yum check-update -- scans the defined repositories for the latest software to download. 

Yum update -- as it says, updates the system to the latest files and programs.

Yum clean all -y -- cleans up all the files once more. 

You will run these as root, or you can use the sudo bash if you have sudo installed already, or have the system run automatically as a cron job. The RPM updates run differently than APT system updates do, and are known to take much longer, a lot longer actually. Here is what I see when I run sudo bash on my CentOS Linux computer:  Like I said before, RPM based Linux systems do take a considerably long amount of time to complete, compared to a Debian based system like Ubuntu. Once these scripts are completed, you will have a fully updated system*, and can continue on with what you were doing. This is a very very simple script. You can add or subtract from this if you want. I happen to use this script on this webserver, and have to remove the chattr immutable flags I have set on many many files to keep them protected from any type of change whatsoever, with out consent. I have had no issue using these commands to do my quick system updates for more than a year now, and it saves time. Side note -- I have heard a few people say before that using the tack y (-y) during an update, or clean is dangerous. I am not going to say otherwise, but I have seen, and used this without any issue before. I guess you will have to decide whether to use it or not "at your own risk" as I have heard it said. * - depending on if no errors occur because of files being locked using chattr, or for any other reason.

Originally posted at

Updated 21-Sept-2010. (Accidentally Deleted a Photo)

Click Here!