Archive for the ‘Linux’ Category

Get current runlevel in Linux

Posted: 27th October 2012 by Tim in Linux
Tags: , , , , , , ,

Runlevel on linux systems refers to the level of operation of the operating system. For example, runlevel 0 is shutdown, 5 is (generally) multi-user with everything enabled, etc. It’s probably best to refer to Wikipedia if you need a more detailed explaination. To query the current run level, you can run the following command: who […]

Each user on a unix system is assigned a user id, or uid. You can see your uid by running ‘id -u’. root will have a uid of zero. So to check if the user running a script is root, you can simply check that id -u is equal to zero, like so: if [ […]

This is an asy one. Let’s say, for instance, you’re living in Japan and connect to the internet via PPPoE. Your service provider informs you that you need to set your MTU to 1454, but when you connect you see it’s set to 1492. You can change this using ifconfig like so: sudo ifconfig ppp0 […]

There are various reasons you may want to set your IP address to be static, one of these being to reduce boot time by removing DHCP discovery. Doing this in Linux is quite straight forward. If you want to make your current IP address your static address, you can find the details in a few […]

In languages like C and Java, if you want to run something 10 times you could write something like for (int i = 0; i < 10; ++i) { … } You can do this in a number of ways in Bash, but one of the easiest ways is like this; for i in {1..10}; […]

Formatting a usb drive in linux

Posted: 11th July 2012 by Tim in Linux
Tags: , , , , , , , ,

So you’ve got a USB drive, and you need to reformat it. You can do this all quite easily on the command line using the fdisk utility. First, get the device location. This will be something like /dev/sdd. You want the location of the device, not a partition on the device ie: /dev/sdd instead of […]

If you want to get the last n characters of a string in bash, you can simply mix bash substrings – ${string:offset[:length]} – with bash string lengths – ${#string}. For example: str=”abcde” n=3 echo ${str:${#str} – $n} will print: cde

If you think you’re debian install starts up too slowly, there’s a very easy way to speed it up: simply add this line to /etc/default/rcS: CONCURRENCY=shell If the file already contains CONCURRENCY=none then replace this line with the line above. This will make the startup scripts run in parallel where possible. Note: may break things […]

Annoyingly, numlock is not turned on by default in Debian or Fedora. Thankfully, the fix is simple. Firstly, install the numlockx program. This is a simple command line tool which can turn numlock on or off: Debian: apt-get install numlockx Fedora: yum install numlockx Next, add this to one of the startup scripts. I like […]

Japanese, like many other Asian languages, is written using a variety of symbols which are not found in the standard ASCII table. Fortunately, you can include these symbols in LaTeX documents using the CJK package. In ubuntu this can be installed via the sudo apt-get install latex-cjk-japanese command. I’m not sure about Windows, Mac or […]

The Amazon Kindle is a great little device which stores it’s documents unencrypted and unhidden on it’s hard drive, just like you would on your PC. This means you can add and remove documents as though it was a USB drive. It’s that easy. But on Ubuntu when you plug it in, nothing happens. The […]

Piping stderr in unix

Posted: 26th May 2011 by Tim in Bash, Ubuntu
Tags: , , , , , , , , ,

In unix, you can pass output from one program to another using the pipe symbol (|). Unfortunately, it only pipes the output from stdout (cout). You can pass the output from both stdout and stderr (cerr) by adding 2>&1 to the end of the command before the pipe, where 1 is the file descriptor for […]

Sometimes in a terminal you want to strip out the first line of output from a command. For example, you may want to generate a list of users which have tasks running using the ps command. This command puts a header at the top of the output. You can remove this header by piping the […]

This is a very specific post about using the £8.97 VGA webcam from Tesco with Ubuntu 10.04, namely with Skype. These instructions might work with other webcams and/or other linux distros, but I have not tested this personally. If this does/doesn’t work for your webcam/distro combination then please leave a comment describing your experiences. Okay, […]

There are a number of ways to convert CDs into MP3s in Ubuntu. For me, the best choice is Sound Juicer because of it’s filename flexibility and ability to deal with compilations. Setting it all up is also very simple. Only two packages are required from the repository. They can be installed with the following […]

Ever jumped onto an Ubuntu server somewhere without knowing which operating system version it’s running? You can find this out with one simple command: lsb_release -a This will provide output like: Distributor ID: Ubuntu Description: Ubuntu 9.10 Release: 9.10 Codename: karmic

Pausing processes in ubuntu

Posted: 6th June 2010 by Tim in Ubuntu
Tags: , , , , , ,

There are times when you want to pause a process and continue it later. For example, when a process is using all the computer’s resources and you need to access something or execute something else. This can all be done via the kill -STOP and kill -CONT commands. First you need to grap the pid […]

Some mail servers require you to connect on a certain port. Evolution (the default mail client for the gnome desktop environment) doesn’t have a setting for the server port number. You can set this by adding :[port_no] to the end of the server address. For example, to use the mail server mail.example.com on port 587, […]

Mounting ISO files in Linux

Posted: 24th April 2010 by Tim in Ubuntu
Tags: , , , , , , , ,

One of the niceties of linux distros like Ubuntu is that you can ‘mount’ ISO files. An ISO file, or ISO image, is an archive of a CD or DVD. By mounting an ISO file, you can read the data as though you inserted the CD into your computer. Ubuntu will even regard it as […]

Let’s say you have a file type whose contents are in XML format but have a different file extension such as .tim . If you want to edit these files with Vim with syntax highlighting, simply add the following to ~/.vimrc (affects only your Vim environment) or /etc/vim/vimrc (affects everyone’s Vim environment): au BufNewFile,BufRead *.tim […]

If you’re getting a FATAL: Ident authentication failed for user [username] Error when attempting to connect to postgres as a specific user, chances are you need to change some security settings. Postgresql, by default, only allows you to connect to postgres if the postgres username is the same as your username on the operating system. […]

The learning curve for LaTeX documents can be a steep one. This step-by-step guide covers installing and setting up the LaTeX environment, and creating and compiling your first document so that you can read and distribute it. Setting up the LaTeX environment A few things need to be installed before we can start creating documents. […]

Playing DVDs in Ubuntu

Posted: 31st December 2009 by Tim in Ubuntu
Tags: , , , , ,

Unfortunately, you cannot play all DVDs in Ubuntu out of the box. Some packages need to be installed manually due to legal issues in some countries. If you find yourself getting errors like VLC is unable to open the MRL, chances are this is your problem. It’s a simple fix (paste this into a terminal/console): […]

Doxygen highlighting is set up by default on most Vim installations, but for some reason it’s disabled. There are two options for enabling it. First, it can be enabled globally. This means adding the parameters to the global Vim configuration. Note that you may need to be root for this to work (ie: sudo echo […]

If you’re trying to compile C programs for Linux on an AVR32 architecture, you’re going to have to get the avr32-linux-gcc cross compiler. Note that you can’t use the avr32-gcc compiler, as this compiler makes programs which do not run on an operating system (ie: they talk to the system directly), which will not run […]