Thursday, 19 June 2008

Untar with wild cards

The tar application doesn't like using wild cards. If you are trying to decompress multiple files in one go you might try a command like:
user@computer:~/archives> tar -xf *.tar
However, this produces multiple errors, one for each file that the wild card matches:
tar: archive1.tar: Not found in archive
tar: archive2.tar: Not found in archive
tar: archive3.tar: Not found in archive
tar: archive4.tar: Not found in archive
tar: archive5.tar: Not found in archive
A quick solution is to use a loop to decompress them one at a time like so:
user@computer:~/archives> for archive in *.tar ; do tar -xf archive ; done

Thursday, 29 May 2008

Viewing display on remote computer on Ubuntu

If you want to use two computers using one screen, keyboard and mouse without using a KVM switch you can use Linux to output the display of one computer onto another.

This method should only be used on a secure network behind a firewall as stated in the documentation:
XDMCP service should run only on trusted networks and you have to disable firewall for interfaces, where you want to provide this service.
Any computer in the local network will be able to access the computers display so it is important you trust every computer.

To start with you need to edit the computer you want access to. As root edit the file /etc/sysconfig/displaymanager. Change the line:
Save the file and exit. You now need to restart XDMCP by typing:
rcxdm restart
Now any computer on the network can gain access to the display of this computer. To gain access use the command on the remote computer:
X :1 -query <IP address of first computer>
If everything has worked the login screen of the remote computer will load. You can switch back to your own computer’s display by pressing ctrl+F7 and then go back to the external computer again by pressing ctrl+F8.

If ctrl+F8 doesn’t work then try some other F keys, it’ll be in one of them.

Wednesday, 28 May 2008

Getting Minicom to work

When running Minicom for the first time you’re likely to be greeted with the following error message:
minicom: cannot open /dev/modem: No such file or directory
This is because Minicom is looking for your serial port in /dev/modem and in newer versions of Linux it’s located in /dev/ttyS0 or /dev/ttyS0. In the following example I will use /dev/ttyS0.

There are two ways to fix this problem. You can either create a shortcut of /dev/modem to point at /dev/ttyS0 or edit Minicom’s settings to use /dev/ttyS0.

To use the shortcut method use the following command:
ln -s /dev/ttyS0 /dev/modem
To edit Minicom’s settings start Minicom with the command:
minicom -s
This will open Minicom with the configuration menu. Use your direction key to scroll down to Serial port setup and press enter. Now press a to edit the Serial Device. Change this to be /dev/ttyS0. Press enter once you have finished editing. Now press escape to go back to the main menu. Finally select Save setup as dfl to make sure that the serial port is correct every time you run Minicom. You can now select Exit to start using Minicom or Exit from Minicom to close Minicom. In the future you can run Minicom without the -s flag

Saturday, 10 May 2008

Changing the display manager

If you wanted to change the display manager you could try stopping the current one and starting the one you want. For instance, if you wanted to stop using kdm (KDE desktop manager) and start using gdm (Gnome desktop manager) you might try the following:
/etc/init.d/kdm stop
/etc/init.d/gdm start
However, this gives an error along the lines of:
Not starting GNOME Display Manager (gdm); it is not the default display manager
To make gdm the default display manager you need to edit the file /etc/X11/default-display-manager. This file should only contain one line - the full path to the desktop manager you want to run. In the previous example the file would contain /etc/init.d/kdm. So I would change it to /etc/init.d/gdm. Now when you type the original commands the Gnome desktop manager will start.

Thursday, 8 May 2008

Calculating percentages in bash

Dividing in bash will cause problems if the result is below zero. This is a problem when you’re trying to work out percentages. For example, if you simply want to divide 1 by 2 the result should be 0.5. However, bash returns the result 0:
user@computer:~> echo $(( 1 / 2 ))
To fix this problem use the program bc, “an arbitrary precision calculator language”. Using bc you can do the calculation to a specified number of decimal places:
user@computer:~> echo “scale=2; 1 / 2″ | bc
You can use this to work out the percentage as follows:
user@computer:~> echo “scale=2; 1 / 2 * 100″ | bc
To chop off the decimal places use sed:
user@computer:~> echo “scale=2; 1 / 2 * 100″ |  bc  |  sed s/\\.[0-9]\\+//

Friday, 25 April 2008

Gracefully exit a bash script on ctrl+C

If a user presses control+c to exit your bash script you may wish for the script to preform some tasks before exiting. To do this you can trap the command. You can use trap along with a function to print a message to the user as follows:

trap stopScript INT
stopScript() {
  echo "Exiting script due to user pressing ctrl+c"


By not putting an exit in your function will cause the script to continue, ignoring the ctrl+c from the user.

Tuesday, 15 April 2008

Reading from and sending data to the COM port in Bash

To read data that is coming from your COM port you need to know what the correct device is. Usually this is in /dev and is called something like /dev/ttyS0. To send data to the COM port simply redirect the output of an echo to the device:
echo "ping" > /dev/ttyS0
This will send the command ping across the COM port to the device.

If you want to read from the COM port you need to concatenate the device:
cat /dev/ttyS0
This command will hand and any data will be printed to your console

Wednesday, 2 April 2008

Creating multiple subdirectories at once

If you want to create a directory with many parent directories that don’t already exist it can be a pain to create each directory one at a time. mkdir provides the flag -p to create all the directories if they don’t already exist to speed this process up and make it less tedious.

To make its use clear here is an example:
user@computer:~> mkdir -pv /tmp/test/directory/subdirectory1/subdirectory2
mkdir: created directory `/tmp/test’
mkdir: created directory `/tmp/test/directory’
mkdir: created directory `/tmp/test/directory/subdirectory1′
mkdir: created directory `/tmp/test/directory/subdirectory1/subdirectory2

Thursday, 13 March 2008

Adding routes automaticly when booting

If you add a static route for your network you have probably noticed that it disappears when you reboot. This can get annoying as you need to re-add it every time.

To have the route added by default every time you boot add the route to the file /etc/sysconfig/network/routes in the form:
Destination    Gateway    Netmask   Device
So if you want all traffic to the subnet to go through gateway you would use:
Note that device isn't required. If you omit it route will try and figure out the device by your Ethernet device’s settings.

If you want to set a default gateway use the destination of

Friday, 7 March 2008

Firefox wont open

After Firefox crashes or you don’t close your browser down properly it may refuse to open again claiming it is already open with a message along the lines of:
Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system
This can be frustrating after you reboot and still have the same message.

The problem is that as Firefox didn't close properly it didn't have chance to delete its lock files. Lock files are just basic text files that programs create when they are launched. When they are closed they delete these files. This is done as when you launch the application, in this case Firefox, it will check to see if that lock file exists. If it does it knows the program is already open and will give you a message like the one above.

To solve this problem all you need to manually delete the lock files. These are located in
In this directory you will see a subdirectory starting with a made up series of letters and digits and ending in .default. Mine is called f1ps0jiv.default. Go into this directory and delete the files .parentlock and lock.

Note the period before parentlock. This means the file is hidden, so you might not be able to see it right away. If you are using your console to delete the file then just type:
rm .parentlock
If you are using a file browser such as Dolphin you will need to select View -> Show Hidden Files to see them

Wednesday, 5 March 2008

dhcpd error

Recently I had to set up a DHCP server. I installed dchp, configured it and ran it using the command:

This ran successfully and assigned IP addresses as expected. However, when I tried to start the service on boot up I got the error message:
root@computer:~>service dhcpd start
Starting DHCP server … cannot… DHCPD_INTERFACE in /etc/sysconfig/dskipped empty!
This was due to the computer having 2 network cards and dhcpd not knowing which interface to listen on for DHCP requests.

To solve this problem I had to edit /etc/sysconfig/dhcpd and modify the line:


to point to the Ethernet device you want to use (generally eth0 or eth1). Once I set this to eth0 the DHCP server started on boot up and ran successfully

Friday, 22 February 2008

Extracting rar files in Ubuntu

Strangely all the distributions of Linux that I've used don’t come with an application to decompress rar files on the command line. To install a simple application to decompress them in Ubuntu type:
sudo apt-get install unrar
Once installed you can decompress your rar file by typing:
unrar x <File>
Where <File> is the name of the file you want to decompress.

Tuesday, 19 February 2008

Installing Starlink/GAIA/Photom on Ubuntu

To start off install the dependencies. Starlink requires C Shell (csh) to run. C Shell is an alternative to the more commonly used bash. To install C Shell type the following:
sudo apt-get install csh
Once installed download the latest version of Starlink. Once your download has finished untar it to /usr/local/bin (Remember to change Linux-32bit-glibc2_5.tar.gz to which ever version you downloaded):
sudo tar -zxvf Linux-32bit-glibc2_5.tar.gz -C /usr/local/bin/
The final step is to source the Starlink profile to set up the environment variables needed by Starlink. This can be done automatically for you by editing your bashrc file. This file is executed every time bash starts, such as when you log in. To edit your bashrc file type:
gedit ~/.bashrc
Add the following to the bottom of your file then save and exit.

#source the Starlink profile so we get the Starlink env vars
source /usr/local/bin/star-namaka/etc/profile

You will need to change “namaka” to whatever version you’re using.

Restart your console to let the new environment variables kick in and then you can run your Starlink applications using one of the commands:

Wednesday, 6 February 2008

Installing NVIDIA Drivers in Ubuntu

Unlike many other video card manufactures NVIDIA produces easy to install drivers for Linux.

To install your NVIDIA card’s drivers first download the correct driver for your card from the NVIDIA website.

Before you start your installation make sure you have the package libc6-dev installed. To do this use the command:

sudo apt-get install libc6-dev

To start installing the driver you will need to kill your xserver. This will mean you will no longer have access to your GUI so it will be a good idea to print out these instructions before doing so.

To kill your xserver just stop the process. If you are using the KDE desktop type:
sudo /etc/init.d/kdm stop
Or if you are using Gnome desktop type:
sudo /etc/init.d/gdm stop
Your GUI will disappear and be replaced with a simple text prompt. Press Ctrl + Alt + F2 and you will be able to log in. Once you have logged in navigate to wherever you downloaded your driver to and make the driver executable by typing (note your driver might be called something slightly different):
chmod a+x
You can now install the driver by typing:
Run through the installation, answering any of the questions. When the installation is complete you can start your xserver again. To start your xserver in KDE type:
sudo /etc/init.d/kdm start
Or if you want to use Gnome desktop type:
sudo /etc/init.d/gdm start
Your GUI should now start up again with the latest driver for your graphics card installed.

Tuesday, 5 February 2008

Storing results of commands in an array

If you want to create an array of directories using bash you might try:


However, this will create a variable containing each file separated by spaces like this:
adm agentx cache games lib lock log mail opt run spool tmp X11R6 yp
To place each item into its own element you simply need to add some brackets:


You can test this has worked with a simple loop:

directories=(`ls /var`)
for (( i=0; i<${#directories[@]}; i+=1 )); do echo ${directories[${i}]} ; done

Sunday, 3 February 2008

Searching the apt-get repositories

If you need to install a package via apt-get but you don’t know it’s exact name there is a simple way of searching the repository to find it.

If, for instance you wanted to install Kopete you would search the repository like so:
apt-cache search kopete
This will return a list of programs that looks like this:
kdeartwork-emoticons - emoticon collections for KDE chat clients
kdenetwork-dev - development files for the KDE network module
kopete - instant messenger for KDE
ichthux-emoticons - Christian emoticons for Kopete
kmess - Instant messenger to use MSN on KDE
kopete-otr - Off-The-Record encryption for Kopete
kopete-plugin-desklist - Kopete plugin which displays online contacts on desktop
kopete-kde4 - instant messenger for KDE 4
kdenetwork-dev-kde4 - development files for the KDE 4 network module
kdeartwork-emoticons-kde4 - emoticon collections for KDE4 chat clients
You can see from this that the package you need is “kopete” or “kopete-kde4″ if you’re running KDE 4.

You can then go on to install the package with:
sudo apt-install kopete

Wednesday, 30 January 2008

Updating Banshee in Ubuntu (7.10)

If you have installed Banshee from the Ubuntu repository then chances are the version you have is out of date.

It may run fine but be missing useful features or support for your MP3 player. These things are obviously worth having if you are a frequent user of Banshee. To get the latest version you will need to compile it from source.

To start with make sure you have everything you need to compile from source:
sudo apt-get install build-essentials
Next you will need to update mono-zeroconf. To do this download the latest version from the mono-project. You need to download the “Source code for Linux/OS X (tar.bz2).” Once your download has finished decompress it with the commands:
bzip2 -d mono-zeroconf-0.7.5.tar.bz2
tar -xvf mono-zeroconf-0.7.5.tar 
You should now have a directory called something like “mono-zeroconf-0.7.5″. Change directory into it and compile and install mono-zeroconf by typing the following commands:
sudo make install
Finally, make sure you have the remaining dependencies installed by typing the following commands:
sudo apt-get install gnome-common automake1.9 monodoc
sudo apt-get build-dep banshee
You can now upgrade Banshee. To upgrade the latest version you again need to compile it from source. Before you do that make sure you uninstall the current version:
sudo apt-get remove banshee
You are finally ready to download and compile the latest version of Banshee. Head over to the Banshee Release Page and download the latest release (tarball). Uncompress your download with the following command:
tar -zxvf banshee-0.13.2.tar.gz
Change directory into the Banshee directory you just decompressed and compile and install:
./configure –prefix=/usr –disable-daap
sudo make install

Sunday, 27 January 2008

Ripping CDs using FLAC format in K3b

After trying to rip a CD to FLAC format with Kubuntu 7.10 I was surprised to find it doesn’t have FLAC as a ripping format option by default.

Getting the ability to use FLAC is simple though, it just requires 2 packages to be installed flac and libflac++6.

To install these just use the following command:
sudo apt-get install flac libflac++6

Saturday, 26 January 2008

Convert DOS newline characters to Unix format in Vi

DOS process text files a little differently to Unix systems. If you write a text file in Windows and then open in in Linux, you may see a ^M on the end of each line. This is just the character that is used on DOS based systems when you press the enter key.

 To get rid of each ^M in Vi use the following command:
To get the ^M character don't type ^ and M! You need to press Ctrl+v and then Ctrl+m

The 1 at the beginning means start at line 1 and the $ means finish on the final line.

s is the search and replace command. It is used in the format of s/string to search for/string that replaces the search string/

The final g is part of the search and replace command. it makes the command global. If you don't have the g on the end only the first instance is replaced.

Wednesday, 23 January 2008

Setting Folding@Home to run on boot up

On Linux Folding@Home doesn't run manually when you boot up your computer. One way around this is to install it as a service. This will make Folding@Home start up in the background every time your computer boots.

To begin download the Folding@Home client. Once downloaded you will need to extract the contents. The best way to do this is to create a folder somewhere and extract there. I created a folder called folding in my /etc directory:
sudo cp -r folding /etc/folding
Once you have extracted all the files make the Folding@Home client executable with the following command:
sudo chmod a+x /etc/folding/fah
Now run the client manually and enter your user details when prompted. Once you have the client set up and running successfully, exit out by pressing ctrl+c:
cd /etc/folding sudo /etc/folding/fah6
Now that you have Folding@Home set up you can create a bash file which will run the client. This script will be used to start Folding@Home for you at boot. Create a text file containing the following code and save it as /etc/init.d/folding:


cd /etc/folding/
./fah6 >> /tmp/folding@home 2>&1 &

Make this bash script you just created executable by typing:
sudo chmod a+x /etc/init.d/folding
Finally you need to add Folding@Home as a service. To do this type the following command:
sudo update-rc.d folding defaults
This command adds the bash script you just created to the system's startup scripts. So now when you boot up, Folding@Home will start, and when you shut down Folding@Home is stopped.

To check the status of Folding@Home at any time you can check the log:
tail -f /tmp/folding@home
Since the log is placed in /tmp it will be removed every time you reboot so you don’t need to worry about it filling up disk space