Browsed by
Category: How To

Recursively Remove .cvs/.svn/.git Directories

Recursively Remove .cvs/.svn/.git Directories

I tend to keep backups using several methods depending on the situation. Some times I run a script that invokes rsync with rolling, date-based backup. Lately I have been experimenting with compressed/dedup archives/filesystems.

One nearly constant annoyance, though, are those pesky .svn, .cvs, and .git directories. They serve a purpose, but not within my backup that already versions its data.

In order to be rid of them I just run rm -rf `find ./ -type d -name [directory to remove]`. If you wanted to, you could stick this into a script within your path:


if [ $# == 1 ]; then
rm -rf `find ./ -type d -name $1`
echo "Script requires one argument."

This would allow you to pass the directory you want to recursively be rid of in whatever directory you call it from. Note this script will not handle spaces in the argument but for this we do not need it.

Minimal Ubuntu 12.04 Install with Only MATE

Minimal Ubuntu 12.04 Install with Only MATE

In a previous article I talked about replacing Unity with MATE on Ubuntu 12.04. It is working out very well for me but I still feel like there is more that can be done. Too many resources are being spent for things that got left over from Unity and it is bugging me.

Minimal Ubuntu Install

First things first, we need to do a minimal install of Ubuntu. You have two options here:

  • You can use the netboot disc. When prompted later in the installation do not install any of the pre-configured setups as we will install the packages we need later.
  • You can use the alternative disc. When the disc first boots just press F4 Mode and select “Install a command-line system“.

I like the netboot option best because it downloads all the latest packages during install so there is less mess. I have also had random problems with it not being able to find some packages since Ubutnu 12.04 was released. If that happens the alternative disc works just as well and will be faster since it has all its packages on the disc. It really does not matter which you choose for our purposes.

Both support encryption and both support RAID so feel free to use those if you like. I will not be covering them or the rest of the installation in this article.

Install MATE

Since everything here requires root just do an sudo -i first. Remember to log out of root (Ctrl-D) before starting MATE. Would be a good idea to do an apt-get update && apt-get upgrade before, too.

First we need to add the MATE repositories. Using nano add the following to /etc/apt/sources.list:

deb precise main
deb-src precise main

Next we need to install the packages (you can answer the hddtemp question however you like when it comes up):

apt-get update
apt-get install -y --force-yes mate-archive-keyring mate-desktop-environment xinit
apt-get update

Now all you need to do is login, type startx, and you are done! … sort of… if you are happy with the way things are you may now go away.


You now have an fast and low-resource traditional desktop at your finger tips with the stability of Linux and all the packages Ubuntu has to offer. I am so proud of you.

On my dinky little Atom-based netbook, with MATE running, this setup eats virtually 0% CPU and ~150MB of memory. Disk usage sits at ~1.7GB which is a little higher than I would like but storage is cheap so I am not too worried about it (probably all the xinit dependencies). Boot time is in the mid-single digits and that is on a 5,400 RPM disk. I imagine a decent USB stick will be very similar but I have yet to test that.

I am very happy with all this. Of course you, dear reader, are not so you will continue reading… blood from a stone, Internet Person…

MATE Extras

As of right now your menus are looking pretty bare and your audio might not work. By virtue of what I set out to accomplish there is very little installed. Here are some packages that may prove very helpful:

apt-get install zram-config preload synaptic gparted brasero mate-media-pulse mate-settings-daemon-pulse mate-bluetooth bluez-cups cups cups-pdf system-config-printer-gnome mate-conf-editor wine libreoffice libreoffice-pdfimport firefox pidgin thunderbird xul-ext-lightning vlc gimp gimp-data-extras jockey-gtk usb-creator-gtk network-manager-gnome

I am sure you will want to install a hell of a lot more but I will leave that up to you. You may want to install less, in which case do an aptitude show [package] to see what a package does before installing.

For some reason there is no supplied way to do “nothing” when the laptop lid is closed. If you want this functionality back start up mateconf-editor, set /apps/mate-power-manager/buttons/lid_ac and /apps/mate-power-manager/buttons/lid_battery to nothing.

Auto Boot into MATE

Maybe you want to automatically boot into MATE. Maybe you are just that lazy. Maybe a white-on-black terminal killed your father and now, as a result, you are too afraid to face one… fear not, citizen! We did not install a display manager since MATE does not currently come with one but we can easily fix all that with a single command:

apt-get install slim

slim is very light weight which is why I chose it. The trade off is it does not support much besides logging you in. After installed just open /etc/slim.conf and set default_user to your username and auto_login to yes (make sure you uncomment both, of course). The MATE Wiki also recommends that you stick exec ck-launch-session mate-session in .xinitrc but everything works fine without it for me so experiment with it.

If you really, really do not want to install a display manager (like me) you could just stick startx at the bottom of .bash_profile (if it does not exist create it). This file sits in your home directory and is executed every time you log in.

Known Issues/Notes

There are a few things that are not show-stoppers for me but I want to spend some time fixing later.

  • Want to get Compiz and all those snazzy effects working. I have been experimenting with varying success. Have not gotten it to work just right yet.
  • I miss my Open With Archive Mounter from nautilus. Just either need to figure out the right package or Caja configuration (not sure which yet).
  • VLC does not inhibit screen blanking when running in full screen. This is really, really annoying to me as I use my netbook for entertainment while on long trips.
  • For some odd reason nm-applet (part of network-manager-gnome) will not start up until you comment out all references to your primary network adapter in /etc/network/interfaces and reboot. I only noticed it after I tried to connect to my wireless network so if you only have a wired connection you may not care about this.
  • Putting startx in .bash_profile may cause an issue if you log in from anywhere other than the terminal. For example, an SSH connection. Also if you need a terminal after breaking X, MATE, or something this might make it harder to fix. I am sure there is a better place to put startx but I have to look up where. For now it is probably better to just go with the display manager method above if you do not want to be bothered.

I am sure I will come across some things as I play with this some more. When I do I will update this article. Please feel free to leave any comments with any issues you find and we will see what we can do about them.

Of course, if you are not insane like me, you could have just installed Linux Mint with MATE in the first place.

Update 2012.09.06
I am not playing with this any longer since I got Linux Mint 13 encrypted up and running. It is not likely I will update this article further. The two are not exactly the same but I have little free time so something has to give.

Replacing Ubuntu 12.04 Unity with MATE

Replacing Ubuntu 12.04 Unity with MATE

I am a stubborn man. But part of that stubbornness was the result of a personal kind of evolution, not an unwillingness to change.

For example, my desktop. Microsoft, with Windows 95, gave us something great: the desktop we know and love. Trying my best to ignore Metro— for the sake of this post, at least– some of my habits have changed to fit this model but, more importantly, I have figured out how to change it best to fit my needs. There is room for improvement but I can only imagine those improvements adding new functionality, not removing old, show-stopping hurdles.

Ubuntu, in their awesome, massive growth and other-wise fantastic direction from their leadership, have decided to make a major change. They have decided to abandon our old friend for something pretty radical with Unity. Unity is, for the most part in its latest incarnation, a pretty great thing. It leaves some old hardware behind (always takes balls but some times is needed) in order to innovate and move us all forward and I have grown to like it for some tasks. For example, my parents and grandparents have flourished using it. They all love different things about it but it works for them and I am happy to use the right tool for the job.

However, although my family finds it easier with is bigger buttons and everything-merged-into-one-place design, I find it much harder to use for what I do. I would call myself a power user and, as such, I have certain requirements. Instead of going into those requirements here I will quote Linus Torvalds because I feel he summed up the meat of it pretty well:

I used to be upset when gnome developers decided it was “too complicated” for the user to remap some mouse buttons. In gnome3, the developers have apparently decided that it’s “too complicated” to actually do real work on your desktop, and have decided to make it really annoying to do.

Here’s an example of “the crazy”: you want a new terminal window. So you go to “activities” and press the “terminal” thing that you’ve made part of your normal desktop thing (but why can’t I just have it on the desktop, instead of in that insane “activities” mode?). What happens? Nothing. It brings your existing terminal to the forefront.

That’s just crazy crap. Now I need to use Shift-Control-N in an old terminal to bring up a new one. Yeah, that’s a real user experience improvement. Sure.

I’m sure there are other ways, but that’s just an example of the kind of “head up the arse” behavior of gnome3. Seriously. I have been asking other developers about gnome3, they all think it’s crazy.

I’m using Xfce. I think it’s a step down from gnome2, but it’s a huge step up from gnome3. Really.

As such I had, for a while, switched to Linux Mint like so much of my cohort. I still love Mint but there is a smaller community there and less Mint-oriented information around the web. Sure, majority of the stuff I have come across for Ubuntu also works for Mint, but I only left Ubuntu because of Unity. If I can remove that annoyance I have no reason not to move back as there is safety in numbers. After all, is that not the whole idea behind the open-source philosophy?

Let us rip that mother-loving (see, I made a funny) interface out and replace it with what was not broken in the first place, shall we?

Remember to backup anything you touch before doing this because who knows if I am secretly working for Microsoft and spreading false information to make people think Linux sucks? It could happen, people!

Open up a terminal and run these commands as root:

add-apt-repository "deb $(lsb_release -cs) main"
apt-get update
apt-get install -y --force-yes mate-archive-keyring
apt-get update
apt-get install mate-core
apt-get install mate-desktop-environment

These will install the necessary packages. Note that you must install mate-core and mate-desktop-environment in separates command for– what I assume is– a race-condition situation. If you do not it may work, or it may break your UI. I never really looked into why as the solution is plenty easy to implement and does not harm anything.

Next you have to change a few configuration files so Ubuntu knows where to find some things. Edit /etc/xdg/autostart/gnome-settings-daemon.desktop as root and replace the contents with

[Desktop Entry]
Name=Mate Settings Daemon

Next edit /etc/xdg/autostart/mate-settings-daemon.desktop as root and find the line that starts with Exec=. Replace it with

Exec=/usr/bin/mate-settings-daemon --no-daemon &

Next edit /etc/X11/Xsession.d/80overlayscrollbars (you may have to create it) as root and add the line


If this is a well-traveled installation of Ubuntu you may also want to change the default text editor to pluma (MATE’s version of gedit) and the default file manager to caja (MATE’s version of nautilus). pluma is not such a big deal– I just hate the latest replaces for the find and find and replace functionally in gedit— but caja added some wwwaaayyy-overdo functionality like undo/redo.

I am not sure if Unity will work after this and I never tried despite it only being a few clicks away. Honestly I do not care one tiny bit. I did notice that a significant amount of memory is no longer being used so my netbook is much happier when I am pushing it a little too hard. Once I get Ubuntu running on my Slate 2 I am also betting it will appreciate the spare CPU cycles, as well.

That crack about sabotaging Linux hurt to write. I owe me an apology. :'(

Cross Compile Allegro 5 Programs in Linux for Windows

Cross Compile Allegro 5 Programs in Linux for Windows

The Allegro game programming library has released v5 of their popular library and with it comes a whole mess of great changes. Thing is, since most of the applications you make with it are going to be games, your main audience lives in Windows. Since I am really upset with Microsofts offerings in this area I needed a way to capture this audience without having to drive myself insane.

What follows is how I am making Windows executables in Linux using Allegro. Please note that I live in Ubuntu (currently 10.10, Maverick Meerkat). You may have to make some slight changes to fit your distro but that should not be a big deal. These instructions assume a clean installation where no other copy of Allegro has been installed (not sure if that would be a problem or not as I have not tested).

  1. Install the required programs:
    sudo apt-get install cmake mingw32
  2. Retrieve and uncompress DirectX:
    Download and copy the DirectX headers and libraries to /usr/i586-mingw32msvc/. Note the file structure within the archive should compare to the mentioned directory. When prompted to overwrite any files do so but make sure you have a backup first in case something explodes.
  3. Retrieve and uncompress Allegro 5:
    Download allegro-5.x.x.tar.gz from their site. Uncompress some place easy to get to. I used my desktop as we can delete this when done.
  4. Compile from source:
    In a terminal type
    cd [path to uncompressed archive] && mkdir build && cd build && cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw.cmake .. && make && sudo make install
    This may take a little while depending on your hardware.

You should now have a functioning cross compiler setup for Allegro 5. Just replace gcc with i586-mingw32msvc-gcc or g++ with i586-mingw32msvc-g++ (for example, I compiled my first test with i586-mingw32msvc-g++ alleg.cpp -lallegro.dll -lallegro_image.dll -lallegro_font.dll -o alleg.exe). The DLLs you will need are in /usr/i586-mingw32msvc/bin/. You may now delete all of our working files on your desktop (or wherever you put them).

There are still one or two things I need to figure out. For one, dynamically linked programs are peachy on Linux; I am comfortable in my assumption that most people using Linux either already expect this or are willing to learn. Windows, not so much. I want to statically link for that platform but I have yet to experiment with that. Another thing is the fact that my current method has Windows opening up a console window in addition to the “main” window. I am sure this is also very simple but have not yet played with it.

Easily Install An Updated Ubuntu Kernel

Easily Install An Updated Ubuntu Kernel

I recently bought a new laptop. Since this laptop is so new and Ubuntu normally ships with kernel versions a few revisions back not all of my laptops features were supported. Bluetooth, for example, is detected but just refuses to turn on. The solution? A newer kernel with newer everything. Sure, I could just update the drivers but this is more fun.

Canonical offers pre-compiled kernels for Ubuntu. All you have to do is go over to and download which ever version you want. Just make sure you grab the headers (all), headers (architecture), and the image (architecture) packages. So if you wanted to upgrade to 2.6.39 you would download linux-headers-2.6.39-02063901_2.6.39-02063901.201106030905_all.deb, linux-headers-2.6.39-02063901-generic_2.6.39-02063901.201106030905_amd64.deb, and linux-image-2.6.39-02063901-generic_2.6.39-02063901.201106030905_amd64.deb. Just make sure you install them in that order and reboot.


Mounting Individual Parititons in RAW Disk Images

Mounting Individual Parititons in RAW Disk Images

Let us say, for the sake of simplicity, that you backup whole disks by using dd in Linux. Now let us assume that you need just a single file out of a backup and do not want to (or can not realistically) restore the whole backup to disk for the single file. You can not mount -o loop because the backup does not contain a single partition. “What to do” you ask? Well I will tell you, wary traveler.

  1. Mount your raw disk image as a loopback device: losetup /dev/loop0 [path to image]
  2. Run kpartx and: kpartx -va /dev/loop0
    This will add your partitions to /dev/mapper/loop0pX where each X is a different partition
  3. You can now mount each partition: mount /dev/mapper/loop0pX /media/partition
    If you want to make sure you do not write anything to your backup simply mount it as read-only: mount -o ro /dev/mapper/loop0pX /media/partition

Once you are finished you will need to do your clean up.

  1. Unmount: umount /media/partition
  2. Remove the mapper devices: kpartx -d /dev/loop0
  3. Remove the loopback device: losetup -d /dev/loop0

These commands may all need to be run as root. If loop0 reports that it is busy just pick another loop device (/dev/loop1, ect).

Clone, Wipe, or Image Media Using dd to Create RAW Disk Images

Clone, Wipe, or Image Media Using dd to Create RAW Disk Images

I recently came across five Windows machines I needed to get working. These were all to be used for the same purpose and thus I would have had to do the same work five times over. I decided to do the work once and then just clone the original disk using dd on Linux.

What follows are a number of example usages of the dd utility:

  • Make an ISO from a CD/DVD:

    dd if=[device] of=disk.iso bs=2048 conv=sync

  • Overwrite a disk with random data:

    dd if=/dev/urandom of=[device]

    One could use /dev/zero instead of /dev/urandom if they just wanted to zero out a disk.
    Darik’s Boot And Nuke might be a better tool for this.

  • Clone a partition:

    dd if=[device partition source] of=[device partition destination] bs=4K conv=noerror,sync

    Create unformatted partitions first.

  • Clone a disk:

    dd if=[device source] of=[device destination] bs=4K conv=noerror,sync

  • Create an image from a disk:

    dd if=[device source] of=[image destination] bs=4K conv=noerror,sync

  • Restore an image to a disk:

    dd if=[image source] of=[device destination] bs=4K


  • Create a compressed image from a disk:

    dd if=[device source] bs=4K conv=noerror,sync | gzip -c > [image destination]

    It would be a good idea to have your image name end with .gz so you later remember it is a compressed image and also clear out temporary directories.

    Adding --fast to gzip will not stress your CPU as badly (good for netbooks and the like). Adding --best to gzip will give you the best compression but drastically slow you down.

    On a well-traveled filesystem zeroing out the free space can lead to huge space savings. In Linux you can use cd [mounted filesystem] && sudo dd if=/dev/zero of=delme-0 bs=1M &> /dev/null ; sudo dd if=/dev/zero of=delme-1 bs=1 &> /dev/null ; sync && sudo rm delme-1 delme-0 on the mounted filesystem (if you have multiple partitions you should do it for each) while Windows offers sdelete -z [drive letter]:. Depending on the amount of free space this could take a good long while.

  • Restore a compressed image to a disk:

    gzip -d -c [image source] | dd of=[image destination]

If you do not have a working Linux installation you can always use a Live-CD. Use fdisk -l or GParted to figure out what a device is named.

Setting a Static IP and DNS in Debian/Ubuntu over the CLI

Setting a Static IP and DNS in Debian/Ubuntu over the CLI

Some times you just need a static IP but have no GUI to easily set one up. Well it is not so hard to do in Debian-based distributions.

  1. Open /etc/network/interfaces in your favorite editor. I like nano.
  2. Find the line that starts with iface [interface]. The interface you are looking for is most likely eth0 or something similar.
  3. Change the line to read iface [interface] inet static.
  4. After it add your IP information. I have included a common example but just replace my information with your own.
  5. Open /etc/resolv.conf.
  6. In it use the nameserver directive to specify your name server(s). The nameserver directive(s) will be searched in the order entered here. Here is an example:
  7. Restart networking with sudo /etc/init.d/networking restart.

[Edit] 2013.08.10
Thanks to Renat Zaripov for pointing out my mistake in typing /etc/resolve.conf instead of /etc/resolv.conf.

Use GRUB2 to Boot ISOs off a Flash Drive

Use GRUB2 to Boot ISOs off a Flash Drive

I will soon need to build a few new PCs that do not have optical drives (one will be a firewall, for example). They do not need the drives for day-to-day usage but I do need to get an OS on them. Since virtually all consumer boards now have USB and I have piles of unused flash drives laying around I decided not to spend the money on an external drive and go the flash drive route.

Here are the steps I took to get my Linux ISOs to boot off a USB flash drive. For these exact steps to work you will need an existing Linux installation (a LiveCD will work just fine).

  1. Create a new, formatted partition big enough to store your ISOs. I am using EXT4 but any filesystem supported by GRUB2 will work. I prefer to use GParted for this.
  2. Mount your new partition. Most Linux desktop distributions will do this automatically for you if you just unplug the device and plug it back in.
  3. Install GRUB2: grub-install --force --no-floppy --root-directory=[path partition was mounted] /dev/sdX where X is the flash drive.
  4. Copy over any ISOs you want to be able to boot to the root of your new partition.
  5. Create [path partition was mounted]/boot/grub/grub.cfg and add the lines

    set timeout=5
    set default=0

  6. In [path partition was mounted]/boot/grub/grub.cfg add any of the following example entries for your favorite distributions:

    menuentry "Ubuntu 10.10 Desktop i386" {
    loopback loop /ubuntu-10.10-desktop-i386.iso
    linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=/ubuntu-10.10-desktop-i386.iso noeject noprompt splash --
    initrd (loop)/casper/initrd.lz

    menuentry "Ubuntu 10.10 Server i386" {
    loopback loop /ubuntu-10.10-server-i386.iso
    linux (loop)/install/vmlinuz boot=casper iso-scan/filename=/ubuntu-10.10-server-i386.iso noeject noprompt splash --
    initrd (loop)/install/initrd.gz

    menuentry "Darik's Boot And Nuke" {
    loopback loop /dban-2.2.6_i586.iso
    linux (loop)/DBAN.BZI nuke="dwipe" iso-scan/filename=/dban-2.2.6_i586.iso silent --

    menuentry "Memtest 86+" {
    linux16 /memtest86+.bin

I could not, for the life of me, get any Windows ISOs to boot using GRUB2. On top of that I came across a number of people trying to do the same thing whom all failed. If anyone gets this working please post in the comments. I may be able to chainload into another boot loader but that is for another day.


Update 2011.02.18
I found this. It may be nothing but it also may be a jumping off point from which to boot from a Windows ISO.

Update 2021.06.16
I finally figured out how to get the Windows installer to boot from a USB flash drive. Thank you to Doc in the comments for kicking me off in the right direction!

  1. First create an NTFS partition. I made mine a second 8GB partition which fit everything comfortably.
  2. Download the Windows 10 ISO from Microsoft. (I know it feels dirty but Microsoft is offering this for free and legit so why not take advantage?)
  3. Copy the entire contents of this ISO onto your new NTFS partition (not the ISO itself).
  4. Add the following to [path partition was mounted]/boot/grub/grub.cfg

    menuentry "Windows 10" {
    set root=(hd0,msdos2)
    insmod ntfs
    insmod chain
    ntldr /bootmgr

Note the line set root=(hd0,msdos2). msdos2 must be set to whichever partition you copied the Windows 10 files to (counting starts at 1, not 0). Also note this is still using MBR, not GPT/UEFI. Maybe I will update with that at a later date but it should not be too hard to figure out.

You will need to disable Secure Boot for any of this to work.

Opening winmail.dat in Thunderbird in Linux

Opening winmail.dat in Thunderbird in Linux

Microsoft, being Microsoft, feels a need to not use the same standard that everyone else has been using for umpteen years. This, of course, creates problems for everyone. A great example of this is their TNEF format which we all see as winmail.dat files in e-mail attachments which does not even work correctly across different versions of Outlook in some cases.

Since I run Ubuntu in my day-to-day I needed a way around this. These are the steps I took.

  • Install the tnef package: sudo apt-get install tnef
  • Create a script in your home directory and make it executable: touch ~/;chmod +x ~/
  • In this newly created file stick


    mkdir $SAVE_PATH
    tnef -C $SAVE_PATH < $1

  • When you try to open the attachment in Thunderbird just tell it to open it with your new script.

Change SAVE_PATH to wherever you would like winmail.dat to be extracted to. You will have a new folder with the extracted contents where ever SAVE_PATH is pointing. If you wanted to, for example, have them extracted directly to your desktop you would want to comment out the mkdir line.