From The Linux Terminal To Shell Scripts
Just a little over a week ago I put together a list called 10 Things To Do After You Install Ubuntu Linux. The list of things to do went as follows:
- Customize the appearance of Ubuntu (wallpaper, theme, fonts, dockbars, etc.)
- Run Update Manager.
- Install Flash, Java, Windows Media Codecs and MS fonts with just 4 clicks!
- Install Compiz Fusion Advanced Settings Manager with one more click.
- Install WINE with one more click and use it to run Windows based software.
- Reveal Archive Manager in the Accessories menu and use it to create zip archives.
- Install the libdvdcss2 decoder so you can watch DVD’s.
- Install Skype from a *.deb file.
- Install Google Earth using Terminal.
- Install Virtualbox.
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get install -y ubuntu-restricted-extras compizconfig-settings-manager wine libqt4-core libqt4-gui && sudo wget http://www.medibuntu.org/sources.list.d/intrepid.list --output-document=/etc/apt/sources.list.d/medibuntu.list && sudo apt-get update && sudo apt-get -y --force-yes install medibuntu-keyring && sudo apt-get update && sudo apt-get install -y libdvdcss2 && sudo apt-get update && sudo apt-get upgrade && wget http://download.skype.com/linux/skype-debian_2.0.0.72-1_i386.deb && sudo dpkg -i skype-debian_2.0.0.72-1_i386.deb && wget http://dl.google.com/earth/client/GE4/release_4_2/GoogleEarthLinux.bin && sh GoogleEarthLinux.bin && wget http://download.virtualbox.org/virtualbox/2.0.4/virtualbox-2.0_2.0.4-38406_Ubuntu_intrepid_i386.deb && sudo dpkg -i virtualbox-2.0_2.0.4-38406_Ubuntu_intrepid_i386.deb* && sudo adduser $USER vboxusers && echo “none /proc/bus/usb usbfs devgid=46,devmode=666 0 0? | sudo tee -a /etc/fstab
NOTE: A couple of the files that are downloaded using the above commands are intended for 32-bit/i386 processors. If you are running the 64-bit version of Ubuntu, read the very last section of this post to see what you need to do differently.
You’re probably looking at that huge command thinking, “What the hell is THAT?!” At first glance, it’s very difficult to see each individual command, much less know what every command does. So I’m going to break it down one step at a time.
Now, as cool as it might seem to copy and paste one long command like this into a terminal window to accomplish all of these tasks in less time, it has its pitfalls. For one, it’s easy to accidentally not copy everything you intend to paste. In addition to this, the entire series of commands usually take longer than the sudo authorization timeout. What that means is, after about 5 minutes or so, another sudo command will be invoked and because it’s been a few minutes since you entered your password for the first sudo, it will ask you for it again. This defeats the purpose of trying to find a way to automate all of these things.
Fortunately, there’s a more reliable way to do this. And it’s called Scripting. More on that later. Right now, I want to break these commands down piece by piece so you can see each one and understand what they do. The commands we’re going to learn about are:
- sudo (Used to gain root privileges in the Terminal)
- apt-get (Used to check for updates, install and remove software)
- && (Used to chain-link commands together into strings)
- wget (Used to download files from the Internet from the Terminal)
- dpkg (Used to open and install *.deb packages)
- echo (Used to reflect input out to a to-be-specified destination)
- The | pipe symbol (routes output from a command into another command)
- tee (accepts text input and can be used to append text files)
The Mega Command — In Baby Steps
Of course one of the first things we need to do is open a Terminal window by clicking Applications>Accessories>Terminal.
Step 2 in our list of 10 things to do says “Run Update Manager.” This is done in the terminal window with the following command:
sudo apt-get update
The very first part of the command you see is the word sudo. As discussed in my Linux Terminal For Beginners blog, this command is what gives the user root-level privileges in a terminal window and it requires the administrator password to be entered in order for it to work. Root access is required for installing software, applying system updates and modifying system configuration files that you normally don’t have permission to edit (among other things). An easy way to remember sudo is to think “Super User DO.”
Following sudo is the command apt-get with the update option added. The apt-get program is used to install, remove, upgrade and even reinstall software packages in Ubuntu. In this case we’re telling apt-get to check the distribution repositories to see what updates are available for your system, and that’s it. Technically this is called resynchronizing your software source indexes.
After this we have:
&&
The two ampersands characters (&&) act sort of like a chain link which tells the terminal, “Once the command preceding && is finished with whatever it’s doing, proceed to execute whatever follows && as long as there were no errors.” By using multiple &&’s, you can daisy-chain multiple commands back to back in a long string. So now you know what all those &&’s up there are all about.
Following && is:
sudo apt-get -y upgrade
This tells Ubuntu to review the list of available updates that were just acquired by the index re-sync, download and install them. The -y option automatically answers “Yes” to the “Do you want to continue” prompt that apt-get presents when you are about to install or remove software. This command is followed by another &&.
Next up we have Steps 3, 4 and 5 in our list:
sudo apt-get install -y ubuntu-restricted-extras compizconfig-settings-manager wine libqt4-core libqt4-gui
This command installs the Ubuntu Restricted Extra’s package (which contains Flash, Java, Win32 Video Codecs, MS Fonts and a couple of other little bells and whistles), Compiz Configuration Settings Manager and WINE. I also added in the libqt4-core and libqt4-gui packages because the Skype installation later down the line depends on them… so I figured we should take care of them now.
While the Ubuntu Restricted Extras are installing, you will have to answer “OK” and “Yes” to the following two screens by using the Tab-Key and Enter Key on your keyboard:

If you happen to know of a way to automate these answers from the command line please let me know!

Step 7: We then come to adding the Medibuntu repositories so we can install the 3rd party libdvdcss2 DVD codec package. The commands needed for installing libdvdcss2 (and what each one does) are outlined in my original 10 Things To Do After You Install Ubuntu Linux. You basically did three copy & paste steps entirely within the terminal window. All I had to do for this little challenge was simply insert &&’s in between these three steps to make one long chain:
sudo wget http://www.medibuntu.org/sources.list.d/intrepid.list --output-document=/etc/apt/sources.list.d/medibuntu.list && sudo apt-get update && sudo apt-get install -y --force-yes medibuntu-keyring && sudo apt-get update && sudo apt-get install libdvdcss2 && sudo apt-get update && sudo apt-get upgrade
And that’s pretty much it. For some reason I had to add a –force-yes after the -y in order to make it answer Yes for you.
Step 8: Next up is Skype. Installing Skype via the terminal consists of using the following two commands chained together with an &&:
wget http://download.skype.com/linux/skype-debian_2.0.0.72-1_i386.deb && sudo dpkg -i skype-debian_2.0.0.72-1_i386.deb
At the beginning is the wget command, followed by a http address. wget (if I’m not mistaken) simply stands for Web Get, and it is used for downloading files off of the Internet from the command line. In this case, it’s downloading the skype-debian_2.0.0.72-1_i386.deb installer file. Normally you would save a file like this to your PC and then double-click on it to start the GUI based installer. But we want to install this package from the command line. We do this using the dpkg -i command, followed by the file name of the deb file we just downloaded. And that’s that.
Step 9: Next up is Google Earth.
wget http://dl.google.com/earth/client/GE4/release_4_2/GoogleEarthLinux.bin && sh GoogleEarthLinux.bin
We use wget again to download a binary installer file, which is then executed by the sh command interpreter (sh GoogleEarthLinux.bin). This will launch the GUI based installer, which unfortunately requires you to click the Install button and then Close the program out for the rest of the string to continue.


Step 10: Finally, we come down to installing Virtualbox. This takes three commands: Downloading the deb file with wget, using dpkg -i to install it, and then using the echo, | pipe and tee commands to append a line of text to the bottom of your fstab file (which grants Virtualbox access to your USB ports). This is done with the following:
wget http://download.virtualbox.org/virtualbox/2.0.4/virtualbox-2.0_2.0.4-38406_Ubuntu_intrepid_i386.deb && sudo dpkg -i virtualbox-2.0_2.0.4-38406_Ubuntu_intrepid_i386.deb* && sudo adduser $USER vboxusers && echo “none /proc/bus/usb usbfs devgid=46,devmode=666 0 0″ | sudo tee -a /etc/fstab
Here we can see wget being used to download a deb file, followed by the dpkg -i command being used to install it. (You will be asked to press the Enter key to select “OK” when a dialog box appears notifying you about Virtualbox creating the vboxusers group).
What we see after that is the echo command. And I’d like to go into a little detail about this very last bit because it’s very cool.
echo does just what it sounds like. It echoes (bounces back/reflects) the input we give it. If you were to type echo “the cat in the hat” in a terminal window, you would see the terminal print back the cat in the hat because you didn’t send it anywhere but to the terminal itself. What we want to do is echo some text to another command that can append our /etc/fstab text file, and in this case, that command is tee. The syntax we’re using is:
- echo “some text” | sudo tee -a /etc/fstab
So how do we get our echoed text to go to tee instead of back to our terminal window? Right after the “some text” part, we see a | pipe symbol. Here’s a picture of what it looks like on your keyboard:

Pipe takes the output that echo spits out and pushes it out to the tee command. The -a after tee stands for append, and it will insert whatever echo sends it into the end of our /etc/fstab file.
Now, let’s take all of this and make a script.
Doing The Above With A Script
A script is nothing more than a text file that contains a list of commands to be executed one after another. So lets start by creating a text file. You can either:
- Click Applications>Accessories>Text Editor
- In Terminal, type gedit and then press Enter.
Once our text editor is open, you’ll want to paste in this line of text at the very top:
- #!/bin/bash
Bash stands for GNU Bourne-Again SHell, and is the default command interpreter used by your Terminal in Ubuntu. While it’s not necessary to include this at the begining (because Bash is the default), it is good practice, as there are other command interpreters out there that may not interpret your script the same way Bash does. This will force whatever version of Linux you are using to use Bash to run the script.
Following this, we can start by pasting in our commands, separating them line by line. I’ve already taken the above commands and put them into a script that you can use. You can download it by clicking here, or from the Terminal type:
- wget http://www.davestechsupport.com/blog/downloads/megascript.sh
To view or edit this script in your text editor, type:
- gedit megascript.sh
You’ll notice that in the script there are no instances of sudo present. That’s because we will be running the script itself with sudo, which in turn gives everything within the script root privileges. So now you won’t have to type your admin password more than once. Now that we have our script, we need to run it. We need to give our script permission to be executed. To do this, type:
- chmod +x megascript.sh
And to run the script, we type:
- sudo ./megascript.sh
As it was in the above steps with Java and Google Earth, you will have to be present at the computer to click “OK”, “Yes” and “Install” to keep things moving. I’ll update this blog if anyone out there knows of a way to automatically send these answers to these programs so that the script is 100% automatic and not depend on user participation for it to finish.
Other Neat Things You Can Try
You could optionally add these three lines of text to the end of the above script:
- echo “The Megascript is finished and your system will restart in 10 seconds! Press CTRL-C to cancel the reboot.”
- sleep 10;
- init 6
The first line echos the quoted text to the terminal window notifying you that the script has completed (well, all of the important stuff has finished, the script is still running). The next command sleep 10 causes the script to pause for 10 seconds. You could hit CTRL-C here if you wanted to interrupt the process. Finally, the command init 6 logs you out of your session and reboots the entire machine, which is a good idea because you likely just finished installing a Kernel update, and the changes you made to your fstab file require a reboot in order for it to take effect.
I got creative with the sleep and echo commands, using them in one-second intervals to have a count-down be displayed in the terminal. I also added a beep to each second with the echo -e ‘\a’ command.
Additionally, you could insert comments after each command in your script using double-pound symbols. For example, the commands in your script could look like this:
- apt-get update ## This checks for the latest updates
- apt-get -y upgrade ## This installed all available updates
Doing this allows you to leave notes that describe the purpose of individual commands in case you forget.
Special Instructions for 64-bit Processors
There are two deb files downloaded in the steps above that are intended for 32-processors. The Skype deb file and the Virtualbox deb file. Skype does not have a 64-bit specific version of their software available for download but there is a chance it will run. However, there are ways to install the 32-bit version on a 64-bit version of Ubuntu. Based upon this guide, I’ve modified the code (and the script). However, I don’t have a 64-bit processor and have not tested this to make sure it works.
Virtualbox does have a 64-bit version of their software available, and it can be downloaded from this address. You don’t need to do this though because I’ve already modified the code for this alternate download and installation.
Here’s the new code:
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get install -y ubuntu-restricted-extras compizconfig-settings-manager wine libqt4-core libqt4-gui && wget -N boundlesssupremacy.com/Cappy/getlibs/getlibs-all.deb; sudo dpkg -i getlibs-all.deb; sudo getlibs -p bluez-alsa && sudo wget http://www.medibuntu.org/sources.list.d/intrepid.list --output-document=/etc/apt/sources.list.d/medibuntu.list && sudo apt-get update && sudo apt-get -y --force-yes install medibuntu-keyring && sudo apt-get update && sudo apt-get install -y libdvdcss2 skype && sudo apt-get update && sudo apt-get upgrade && wget http://dl.google.com/earth/client/GE4/release_4_2/GoogleEarthLinux.bin && sh GoogleEarthLinux.bin && wget http://download.virtualbox.org/virtualbox/2.0.4/virtualbox-2.0_2.0.4-38406_Ubuntu_intrepid_amd64.deb && sudo dpkg -i virtualbox-2.0_2.0.4-38406_Ubuntu_intrepid_amd64.deb* && sudo adduser $USER vboxusers && echo "none /proc/bus/usb usbfs devgid=46,devmode=666 0 0" | sudo tee -a /etc/fstab
And here is an 64-bit version of my script: megascript64bit.sh
- wget http://www.davestechsupport.com/blog/downloads/megascript64bit.sh
Use the same method to give it execute rights and then run it by typing sudo ./megascript64bit.sh
November 13th, 2008 at 8:57 am
Hi Dave,
The code to install Medibuntu is not working for me.
Everythin else works fine.
Very good post - I like the way you explained all the Terminal commands.
Keep ‘em coming!
November 14th, 2008 at 12:17 am
xosted:
Wordpress was causing the double-hyphen placed before the word “output” to be blended together into one hyphen so it wouldn’t paste over correctly. I’ve made a correction above to accommodate for this.
November 14th, 2008 at 1:12 pm
Hi David,
Thank you for the mail.
The new code works fine. Cheers.