Linux For Cynics One user's experiences with Linux


Using pkg-config to Find Library Names

If you are trying to use a library in your program, of course you need to link with it. How do you know what it's called? Use pkg-config! From the pkg-config man page

The pkg-config program is used to retrieve information about installed libraries in the system. It is typically used to compile and link against one or more libraries. Here is a typical usage scenario in a Makefile:

program: program.c
cc program.c $(pkg-config --cflags --libs gnomeui)

Here are some common usages:

List all installed libraries:

pkg-config --list-all

List what compiler flags you need for somelib:

pkg-config --cflags somelib

List what linker flags you need for somelib:

pkg-config --libs somelib

Then there's also --static if you're compiling statically.

pkg-config outputs in a format that is ready for gcc, so you can use backticks to run it and get the output when invoking gcc on the command line:

gcc program.c `pkg-config --cflags --libs zlib`

Or if you use a makefile you can capture it in variables:

LIBS := $(shell pkg-config --libs zlib)
CFLAGS := $(shell pkg-config --clfags zlib)


Improve Font Rendering in Debian

After installing Debian Testing (Wheezy), and started using Firefox (aka Iceweazel), one of the first things I noticed is that the default font rendering in Debian is not pretty.

Luckily, fixing this is very straight foward. Create a file called .fonts.conf in your home directory, and put the following contents in it:

<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
 <match target="font">
  <edit mode="assign" name="rgba">
 <match target="font">
  <edit mode="assign" name="hinting">
 <match target="font">
  <edit mode="assign" name="hintstyle">
 <match target="font">
  <edit mode="assign" name="antialias">
  <match target="font">
    <edit mode="assign" name="lcdfilter">

This will enable subpixel-hinting and font-smoothing. Now just restart (log out, then back in again). Read more here:

Here's the before and after (before is on the left):


Set Keyboard Repeat Delay and Rate

In order to change the key press repeat delay and rate we use a command called


which is a user preference utility for X.

This command:

xset r rate DELAY RATE

where DELAY and RATE are replaced with actual values, in milliseconds. for example:

xset r rate 200 20

First, use

xset q

to see what the current values are. As shown above, I have mine set to 200 delay and 20 repeat rate.

To make this permanent, add that line to your ~/.xinitrc

xset can be used for a lot more than this. As always, use

man xset

to find out more about this command.


Create Screenshots from Terminal Emulator

Probably the simplest way to create screenshots is using the commands


which dumps an image of an X window and


which is a member of the ImageMagick suite of tools. It can be used for much more than converting image formats, but that's what we'll be using it for this time.

Screenshot of Whole Screen

So, to take a screenshot of your whole screen and call it capture.png, run this:

$ xwd -root | convert - capture.png

Add a Delay

Let's say you want to add a delay before the screenshot is taken (say, to move the terminal window out of the way), then simply add a sleep command before the others. For example:

$ sleep 3; xwd -root | convert - capture.png

adds a three second delay before the x window is dumped, and converted to a png.

Screenshot of Single Window

The "-root" argument to xwd tells it to capture the entire X window tree, the whole screen. If you leave it off, you will be given a cursor to click the window you want to capture.

So, if you just want to take a screenshot of a single window, then just run:

$ xwd | convert - capture.png

And click on the window you want.

I say "terminal emulator" because the xwd command relies on X to be running. This would not work on a login without X running.


Using MD5 to Verify Downloaded Files

An MD5 sum is a string of numbers and letters used to verify the integrity of a file. If two files are identical, then they have the same MD5 sum. Here's an example of how to use it:

Let's find a file to download, such as the Crunchbang Linux installer image:


Notice how it has the MD5 sum to check against under the download link? Once we have it downloaded, we can run md5sum to generate the checksum for the file we have on our disk:

$ md5sum crunchbang-11-201330119-i686.iso

Now just check to make sure that the resulting string is the same as the one listed! If it's the same, then the file on the server is identical to the file you downloaded.

Filed under: How to No Comments

List Installed Packages in Debian or Ubuntu

In order to display the list of installed packages, use this command:

dpkg --get-selections

Chances are you have a lot of packages installed, so use grep to find something particular, for example, to see any packaged with the word "gnome" in their name:

dpkg --get-selections | grep gnome

Or, if you want to see how many packages you have installed, you can use the wc program:

dpkg --get-selections | wc

The first number is the number of lines dpkg output, and since there is one line per package, it is the number of packages installed.


Minimal Debian Install

Here's my guide to installing a lean Debian desktop. I went through these steps on a Thinkpad X200. Your needs may vary. Skip the parts that don't apply to you. This post will get you from zero to a working desktop. I will cover additional configuration and customization in another post.

Debian Net Install

First, get the net installer here: Debian Install Images. I went with the current Testing version, Wheezy. It should be suitable for most desktop users.

Because this is a net install, make sure you have an ethernet connection. Wireless won't do.

I'm assuming intermediate level experience with Linux in this guide so I won't go through each step of the installation. I'll leave paritioning and all that to you.

Once you get to the "Select and install software" step, select only SSH Server, Laptop Tools, and System Utilities.

Install sudo

If you did not supply a root password, sudo is already set up and you can skip this step. If you did provide a root password, you need to do it yourself. Time to install sudo and add yourself to the sudo group. This is not strictly necessary, but there are many benefits to using sudo over su. Let's say your username is dave.

$ su
# apt-get install sudo
# adduser dave sudo
# exit

Log out and back in again and there we go!


This isn't necessary if you don't have a wireless card, naturally.

As for me, this is a laptop, so I need to install wifi drivers. I installed using an ethernet cord but that won't do in the long run.

First, we need to add the non-free Debian repositories. Add these lines to the /etc/apt/sources.list file:

deb wheezy main contrib non-free
deb-src wheezy main contrib non-free
deb wheezy/updates main contrib non-free
deb-src wheezy/updates main contrib non-free

I wanted to use vim to do so, but it wasn't added. So, I installed vim:

$ sudo apt-get install vim

Once the non-free repo is added, update and install the driver I need. You might need different firmware:

$ sudo apt-get update
$ sudo apt-get install firmware-iwlwifi

Also get the wireless-tools package:

$ sudo apt-get install wireless-tools

So we have the driver, but now we need to use it!

Since the iwlwifi module is automatically loaded for supported devices, we need to reload this module to access installed firmware:

$ sudo modprobe -r iwlwifi ; modprobe iwlwifi

Now we see if the device has an available interface:

$ sudo iwconfig

Yep! Mine is called wlan0

Configuring your wifi can be done now through the terminal using wpa-supplicant, or you can wait until we have a GUI. I'm going to show you how to use wpa-supplicant because it's harder.

Time to use wpa-supplicant (installed with wireless-tools) to connect to my wireless network. Let's setup wlan0 with the SSID and PSK. Edit /etc/network/interfaces and add these lines:

auto wlan0
iface wlan0 inet dhcp
    wpa-ssid YOUR-SSID-HERE

Now let's see if it worked.

$ sudo ifup wlan0
$ sudo ifconfig wlan0
$ ping router-ip-here
$ ping

Yep! all good.


Okay so installing X is very easy:

$ sudo apt-get install xorg

We could startx now, but that would just give us an xterm. So let's choose a window manager. I'm avoiding full-blown Desktop Environments (such as GNOME or KDE) because this is supposed to be a light-weight install.

My favorite tiling WM is dwm, and my favorite floater is Openbox. I think I'll install them both, as sometimes things work in Openbox and not in dwm (such as screen sharing in Google Hangouts...I dont know why).

First the easy one, Openbox:

$ sudo apt-get install openbox

Because the scripts in /etc/X11/Xsession.d will eventually run x-window-manager, which is presumably set to openbox via the alternatives mechanism (/usr/sbin/update-alternatives --display x-window-manager), at this point you could type

$ startx

And start using Openbox right away, but I'm going to focus on dwm since it's my favorite.

Install your favorite window manager or desktop environment. I like dwm. But, because dwm is configured by modifying the source code and recompiling, it is best not to install it through the repositories (although that is an option if you don't care to change the defaults). The best way to use dwm is by using git, modifying the source, and compiling it yourself. Here's a guide. It can be summarized as the following:

Installing dwm "properly" means downloading the source, modifying it to our liking, and compiling it. This is because dwm doesn't use configuration files or scripts to customize it, the source itself must be changed.

So that means we'll need gcc, et al. If you're a programmer you'd get these things anyway:

$ sudo apt-get install build-essential

dwm requires x11 development libraries, as well as Xinerama development libs (if you want dwm to support mult-monitor). So install those too:

$ sudo apt-get install libx11-dev libxinerama-dev

Now let's get the dwm source code. I'm gonna use git.

$ sudo apt-get install git

And get the source from the suckless git repo:

$ git clone

That will create a directory called dwm.

$ cd dwm

Now make a copy of the config.def.h file so your configuration doesn't get clobbered if you download the source again:

$ cp config.def.h config.h

Make any changes you want to config.h. I won't go into it here.
And finally, compile and install dwm!

$ make clean install

In order to use dwm, we need to make startx use it. So let's create and modify our ~/.xinitrc

$ vim ~/.xinitrc

And add this line to the end of it:

exec dwm


Now just run:

$ startx


Now we have a desktop.


Let's install alsa.

$ sudo apt-get install alsa-base alsa-utils

And get it started:

$ alsactl init

And now test it to see if we can actually hear anything:

$ aplay /usr/share/sounds/alsa/*

Should hear a woman's voice saying "Front center" etc.

Something else you might start hearing is an annoying beep. This is called the PC bell. Disable that damned PC bell.


Disable PC Speaker Beep

This will work in Ubuntu, Debian, Arch, or pretty much any other distro. The PC speaker can be disabled by unloading the pcspkr kernel module like so:

sudo rmmod pcspkr

To make this permanent, blacklist the pcspkr module by adding this line:

blacklist pcspkr

to a file in /etc/modprobe.d/. Name the file something that ends with ".conf". This is how I did it:

echo "blacklist pcspkr" > /etc/modprobe.d/nobeep.conf

You're notice pcspkr is blacklisted by default in Ubuntu. Here's a line from /etc/modprobe.b/blacklist.conf in 12.10:

# ugly and loud noise, getting on everyone's nerves; this should be done by a
# nice pulseaudio bing (Ubuntu: #77010)
blacklist pcspkr

I agree! It is an ugly noise that gets on my nerves. Be gone!

Filed under: Hardware, How to No Comments

Git in Color

To enable color in git, simply use this command:

git config --global --add color.ui true

That adds the following lines to your .gitconfig:

        ui = true

There, now you'll see git's greens and reds, which make it much easier to see what's changed.

Don't worry, the color codes will only be used in interactive mode and not when piping output from git to other programs.

Tagged as: No Comments

Make Nautilus –no-desktop Default

If you want to use the Nautilus file manager without it trying to manage your desktop, here's a way to make it always run with the --no-desktop option:

Rename the nautilus binary to something else:

sudo mv /usr/bin/nautilus /usr/bin/nautilus.original

Then create a script called nautilus:

sudo touch /usr/bin/nautilus

And open it in your favorite editor make it run nautilus with the --no-desktop option (as well as any other options passed to it) by giving it the following contents:

nautilus.original --no-desktop $@ &

Make it executable:

chmod +x /usr/bin/nautilus

And there you go! Clearly, this trick can work with anything else you want to apply default options to but cannot simply be aliased in baschrc (because not everything is invoked using bash, of course).

If you want to change it back to normal, just replace the "nautilus" script with nautilus.original.