Shell Scripts


Shell Scripts

Here are some small shell scripts I have written over time. Usually they are tested on Linux with a GNU userland but should work in any POSIX compatible environment.

This scripts are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You are free to do with them what ever you want.


Sort of “cd with bookmarks” for Zsh. You define bookmarks for directories in ~/.bcdrc and then use:

bcd some-bookmark

to cd to the directory associated with some-bookmark.

You can add a bookmark using:

bcdadd some-bookmark

To remove a bookmark use:

bcddel some-bookmark

Or just edit ~/.bcdrc with your favourite editor.

Format of ~/.bcdrc is:




With that you can use:

$ bcd uls

to cd to /usr/local/stow.

Calling bcd without arguments prints the bookmarks:

$ bcd
       ul --> /usr/local
      uls --> /usr/local/stow
   nspool --> /var/spool/news

bcd and bcddel come with completion for Zsh and Bash:

zsh:$ bcd ul<TAB>
Completing bcd bookmarks
       ul --> /usr/local
      uls --> /usr/local/stow

bash:$ bcd ul<TAB>
ul   uls

bcd works with any POSIX /bin/sh if you remove the completion stuff at the end of the file.


File Size Modified MD5
bcd 3.1 KByte 2012-05-18 01:58 4ac441febc7df07c9ef0226a480cb9c2

Save the file as e.g. ~/zsh.d/bcd and add:

. ~/zsh.d/bcd

to your ~/.zshrc. Don’t try to execute the file. This will not work!


Counts the class attributes used in a HTML document.

Needs xmllint distributed with libxml


File Size Modified MD5
cntclass 534 Byte 2009-06-07 06:29 d28890beb93f75cf210e26aa5a18f576


$ cntclass
     1 autor
     1 nav
     1 navactiveitem
     1 navlevel0
     1 navopen
     1 validate
     2 section
     3 navlevel1
     4 navpassiveitem
     5 navitem


Ask HAL about your hardware.

Calling dave with two arguments $1 and $2 lists all device objects for which key $1 has the string value $2.

Calling dave with three arguments $1, $2 and $3 lists the value of key $3 for all device objects for which key $1 has the string value $2.

Note that $2 always refers to string value so dave doesn’t work for keys that have values of other types. That’s a limitation of hal-find-by-property .

Needs hal-find-by-property, hal-get-property and lshal (all distributed with HAL).


File Size Modified MD5
dave 645 Byte 2009-06-07 06:29 d3e03cba054d1792cabf8c713fb6e8e8


$ dave block.device /dev/sda
udi = '/org/freedesktop/Hal/devices/storage_serial_SATA_WDC_WD800BB_22J_WD_WCAM9C068403'
 block.device = '/dev/sda'  (string)
 block.is_volume = false  (bool)
 block.major = 8  (0x8)  (int)
 block.minor = 0  (0x0)  (int)

$ dave linux.subsystem input info.product
ImPS/2 Logitech Wheel Mouse
Macintosh mouse button emulation
AT Translated Set 2 keyboard
PC Speaker
Power Button (CM)
Power Button (FF)


Prints the total play time if all tracks on a video DVD.

Needs lsdvd. Maybe it only works with GNU date (didn’t check if the needed features are defined by POSIX)


File Size Modified MD5
dvdtime 543 Byte 2009-06-07 06:29 4805aa959da211a28e1a5761c0f11f76


$ dvdtime /dev/dvd
libdvdread: Using libdvdcss version 1.2.10 for DVD access


Prints the names of the currently used Firefox profiles. Tested with Firefox 3.0.x

Needs lsof, GNU xargs


File Size Modified MD5
ffprofiles 581 Byte 2009-08-25 20:11 50b25cc2a8682359555fa37efaa6f76f


$ ffprofiles


Displays messages from text files that have changed since its last run.

gmotd looks for files in /usr/local/share/gmodt and displays the ones that are newer than the file ~/.gmotd one by one. After all files are displayed ~/.gmotd is updated.

The folder for the message file can be changed in the script.

You may add this script to the user desktop’s autostart programs to display new messages (created by the admin, cron jobs, ...) after you login.

Needs zenity


File Size Modified MD5
gmotd 870 Byte 2011-08-29 21:06 c6f8f4941b969e30a7b0d93fb2e15659


Open a Windows .lnk file in Linux. This script is the result of a discussion on

By default it looks for the file on the same partition as the .lnk file. You can define a mapping between Windows drive letters and Linux mountpoints in ~/.openlnkrc that has to look similar to this:

C: /media/C
D: /some/other/mount point

The script parses .lnk files just by searching for something that looks like a Windows file name. It doesn’t deal well with non-ASCII characters in file names.

Files are opened using xdg-open.


File Size Modified MD5
openlnk 817 Byte 2009-06-08 07:32 2271d1133b2a7de0599e055842e25273


Microsoft now has published the file format for .lnk files (thanks to Vain for the link). So maybe someone wants to write a better version of this...


Downloads the classifier list from PyPI, displays a list where you can select classifiers and prints the selected classifiers.

Needs zenity, tempfile and wget


File Size Modified MD5
pypicats 977 Byte 2009-07-17 23:01 f510e6bd7bf6271a8c3ae9116a8e65ef


Sleep until a given time. See the date documentation for how to specify times.

Needs GNU date.


File Size Modified MD5
sleepuntil 518 Byte 2009-06-07 06:29 f59773cbf32df38cd63feb30eab30b83


$ sleepuntil '0:00'
$ sleepuntil tomorrow
$ sleepuntil '0:01 1/1 next year'


Switches to a window of the application that has a give PID.

Needs wmctrl.


File Size Modified MD5
switch-to-pid 478 Byte 2009-06-07 06:29 f7357713eb12a83472b097e8eb368f50


$ switch-to-pid $(pgrep firefox)


Fetches the current strip from xkcd and sets it as wallpaper. The mouseover text is added at the bottom of the image.

Needs wget, mktemp, ImageMagick and a desktop environment that uses Nautilus 3.x to manage the wallpaper (like Gnome3 or Unity)


File Size Modified MD5
xkcddesktop 1.0 KByte 2015-01-14 23:18 a9244c3bac7bdb161bd4b35c0c256a91