Tips and Tricks

Execute A Command Of Your Choice When You Press A Certain Key

If you work in the console, you can re-define the keyboard-mappings of any key, so that this key executes any command of your choice.

For this to work, you first need to find out the keycode of the desired key, e.g. F12. You do this by executing showkey, and then pressing F12. Showkey will now show you this output:

$ showkey
press any key (program terminates after 10s of last key press).
keycode 28 release
keycode 88 press
keycode 88 release

Keycode 28 (release) means that you just released your ENTER-key.
Keycode 88 (press and release) is shown because you just pressed and released F12.
The showkey command will end after you have waited 10 seconds without pressing any key.

Repeat this procedure as often as necessary to find out all the keycodes you need.

Now we can change the so-called Kernel String Table , by issuing the command loadkeys, and then entering your strings.

$ loadkeys
keycode 88 = F12
keycode 125 = F40
string F12 = "ls\n"
string F40 = "mikmod -rp /usr/local/data/mod/*.mod\n"

Now press CTRL-d to leave loadkeys. That's it.
Everytime you press F12 you will get the output of ls on your console, and everytime you press the left Windows-key (keycode 125) mikmod, my favorite MOD-player, will be started.
You can now execute your favorite (console-)applications with just one keypress.

You can of course automate this whole precess. Just put your "keycode"- and "string"-lines in a file, say ~/.keystrings, and put a similar line in your boot.local or a similar file:

loadkeys /home/user01/.keystrings

Now everytime you reboot your computer, your key-settings are automatically loaded.

Change The Current Text Console Using chvt

You all know you can change from one text console to another using ALT-Fx, where x is a number from 1 to 7 (or even higher, depending on your configuration).

What is not so widely known, is that you can also change consoles with a nifty little program called chvt.

Example: chvt 3 (this switches to console 3)

There are several reasons why this utility can be quite handy: First, you might want to write shell/perl/whatever scripts which switch the consoles, which you can do now. Second, if something with your X11 keyboard configuration screws up (e.g. ALT-keys don't work anymore) or something similar, you can still switch to a console.

How To Disable Those Annoying Beeps

Here's a short description of how you can disable those annoying beeps in the console and in an X11 session.

  • Console:

    • Disable: setterm -blength 0
    • Enable: setterm -blength 200
  • X11:

    • Disable: xset b off
    • Enable: xset b on

How To Print Several Pages On One Sheet Of Paper

You can use the psnup utility from the psutils package to print several pages of one Postscript file to the same sheet of paper.


  • psnup -2
    Print two pages from per page. Save the output to
  • psnup -4
    Print four pages from per page. Save the output to

There's also a pdfnup utility in the pdfjam package which can do the same thing with PDFs.

How To Start Multiple X11 Sessions

If you want to run two or more X11 sessions on the same computer at the same time, you can do the following:

  1. Switch to an unused console
  2. Type startx -- :1 to start a second X11 session


  • To switch to the new X11 session you can use ALT-F8 (instead of the usual ALT-F7).
  • This only works if you don't use tty8 for a normal text console, i.e. you may not have an entry like
    8:23:respawn:/sbin/getty 38400 tty8
    in your /etc/inittab file.
  • You can also type startx -- :2 to start a third X11 session etc.
Syndicate content