Here's a collection of stuff I've built up from my daily job
tasks. Probably nothing real astonishing, but they might be useful if
you can't or are too lazy to figure them out yourself.
- Mouse Wheel emulation
- My wife wanted her Logitech TrackMan Marble FX's Little Red
Button to work as it does in Windows. That would mean that whenever
the button is pressed, the window scrolls with mouse movement. I
found the trick on a newsgroup:
In /etc/X11/XF86Config (or wherever is appropriate for your system)
Section "InputDevice"
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "MouseManPlusPS/2"
Option "Device" "/dev/psaux"
Option "Buttons" "4"
Option "Emulate3Buttons" "no"
Option "YAxisMapping" "4 5"
Option "XAxisMapping" "6 7"
Option "EmulateWheel" "1"
Option "EmulateWheelButton" "4"
EndSection
- File type conversion
- This is a bash command line to convert PDFs to PSs. Presumably
one could use this for any conversion utility requiring input AND
output file names.
for i in `ls *.pdf | cut -d. -f1`; do pdf2ps $i'.pdf' $i'.ps'; done
- Multiple file compression
- I have a directory tree full of old log files that I keep
individually gzipped. Since the logs come by mail there's no way to
compress them as they come in. Here's a one-liners that finds and
gzips anything that isn't already.
find . -type f -not -name "*\.gz" -exec gzip -9v {} \;
- Copying a directory tree
- If you're not lucky enough to be using GNU cp (with the -R
option), the next best thing is tar. I didn't come up with this
one, and in fact this exact syntax is out of a shell scripting
class. I figure that just about everyone has seen this before, but
it's not always intuitive to figure out the exact command.
cd /; tar cf - etc | ( cd /tmp; tar -xf - )"
replace the "cd /", "cd /tmp",and "etc" appropriately and you're
all set. If you're copying system files you'll probably want to use
"-p" on the extract side. Trust me.
- Killing a range of processes
- Recently, due to a wacky networking issue, I had some 200+ sendmail
processes sitting around waiting for data that would never arrive.
Since valid mail was once again flowing, I didn't want to bring down
sendmail, or even -HUP every sendmail process on the system. Thanks
to Linux's use of monotonic PIDs, though, I could see that all of the
processes I wanted to bump off were in a certain range. The following
ugly hack did the trick:
kill -HUP `ps ax |\
perl -wne 'next unless /sendmail/ ; @fields=split() ; print "$fields[0]\n" if 9300 < $fields[0] && $fields[0] < 10565'`
- Partition table backup
sfdisk -d /dev/sdX > backupfile
sfdisk --force /dev/sdX < backupfile