Shell scripts

Here are some shell scripts I've written for myself over the years.

Adding up numbers is very uplifting.
Attempt to determine whether we are running inside a GNU screen session by chasing parent-pids. If we get to init without finding a screen, we're outside screen.
Backs up a Gentoo system, using the Gentoo package tools to exclude all files from the backup that are managed by packages. That is, back up user and configuration files, excluding system software. No need to waste backup media on stuff that can just be recompiled.
Who's using my bandwidth?
How long has a process been running? Do you have the /proc/###/stat format memorized?
Find and merge identical files. IE, delete one of them and replace it with a hard link to the other. Prompts for files with dissimilar owner/permissions.
A tiny countdown timer.
Named counters. Produces values that increment between invocations. Especially handy for scriptlets called from xargs, there being no shared environment between invocations in that case.
dong, filesinpar
"DO NewsGroup". Sic this on your usenet download directory. It will attempt to par2-recover and extract everything that you've downloaded.
A count-down to doomsday. Calculates the rate at which the filesystem is filling up and tells you when you will run out of disk space.
Nintendo DS homebrew roms are padded with 0xff bytes at the end. If you have a cart that doesn't require the padding, removing it is trivial and saves disk space. There are some awfully large programs circulating to perform this very simple task. Here's one that's tiny and transparent.
dups, rmdups
Find and remove duplicate files, respectively.
Accurately determine the bitrate of a media file.
fastplay, fastplay-sox, fastplay-ladspa, fastplay-soundstretch
Various attempts to make mplayer play pitch-correct audio at non-standard speed. These are now moot, as mplayer 1.0_rc2 has a scaletempo audio filter built right in. Use "-af scaletempo" or put "af = scaletempo" in ~/.mplayer/config and then just change the speed normally with [ and ].
Scale an image with Gimp script_fu.
Sort lines by their length.
My oldest bin packing script. Arrange some files to try to fit them onto CDs/DVDs.
Merge two files with a preference toward non-zero bytes. Good for trying to get a (more) complete file from multiple copies that each have holes in them. Available in C (fastest), lisp, and perl (slowest).
Determine the length (in seconds) of a media file by playing it into | wc -c
Edit filenames with sed commands to rename files.
Edit filenames in your $EDITOR to rename files.
mvto cpto lnto
File management helpers for xargs. They take the destination first instead of last.
Overwrite a file with a newer version, first emitting a diff
Demonstration of talking to kdialog over dbus to update a progress bar.
My homegrown, overgrown, random-order mp3 player. Superseded by mpd.
rows, cols (same script, link one to the other)
How big is your terminal according to the TIOCGWINSZ ioctl?
speedcode, media-group
speedcode re-encodes audio into fixed-bitrate mp3 while shifting speed. I use this for my ipod, which doesn't deal well with variable bitrate or other random properties of mp3s found in the wild. media-group groups smaller files into hour-long chunks to minimize the effect of the ipod's random track-skipping problems.
This is how a geek tunes a piano.
Tool of Objective Truth. Submits things to google to count the number of hits, sorts by the number of hits. Whatever has the most hits is obviously the most true.
Which subreddits does a user post to?
urlencode, urldecode
Command-line pass-through to PHP's urlencode/urldecode functions.
vcd-clean, ripvcd, vcd-loader
Rip a VCD. VCDs are required to have a certain minimum on-disc bitrate so that VCD players can count on off-the-shelf CD drives not spinning down on them during credits and other low-activity scenes. To acheive this without re-encoding the mpeg stream, the VCD format allows and encourages VCD authoring software to insert whole 2048 byte blocks of zeros into the stream. When storing these on hard drives, these zero blocks just waste space. So, vcd-clean removes them, ripvcd invokes vcd-clean and writes to a nice filename, and vcd-loader invokes ripvcd continuously with incrementing filenames, waiting for tray-close to continue.
Many disreputable service providers provide policies and legal statements that you must agree to in order to do business with them that contain a clause along the lines of "We reserve the right to materially change this document without notice to you, and you agree to abide by whatever new restrictions we choose to impose on you." While this is crap and we as a society should simply not do business with these organizations, in the mean time, until enough people are informed and care and we can stage an effective boycott, the least we can do is actually watch these self-changing agreements and see what new clauses are being added otherwise behind our collective backs. This script does just that. I run it from cron, once a week, and it emails me a diff summary of all the changes in several online mutating legal documents.
A bot that complains about the weather. People feel silly doing it after it's automated.
Identify the process that is holding a fcntl lock on a given file.