Linux Commands

Convert a PDF to greyscale

gs -sOutputFile=grey.pdf -sDEVICE=pdfwrite \
  -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray \
  -dCompatibilityLevel=1.4 color.pdf < /dev/null

Source: http://vince-debian.blogspot.com/2008/05/pdf-conversion-to-grayscale.html

URI Encoding an image

I've known for some time that it's possible to embed an image into CSS (useful for greasemonkey scripts), using a format like so:

url(data:[mimetype];base64,[data])

...where [mimetype] is the mime type of your data (eg, image/png).

It's eluded me until now how exactly to get at the [data] bit of this equation. This is simply the base64 encoded string of the actual bytes of the file, which you can get like so:

cat foo.png | base64

This will spit a bunch of garbage to your screen, which you copy and paste into the [data] placeholder.

Changing partition labels

Change an ext2/ext3 partition label

View current label

sudo e2label /dev/niobe/home

Change label

sudo e2label /dev/niobe/home home

Change a fat32 partition label

$ sudo apt-get install mtools
$ mount   # note device path (e.g. /dev/sda2)
$ cp /etc/mtools.conf ~/.mtoolsrc
$ echo 'drive i: file="/dev/sda2"' >> ~/.mtoolsrc   # use the device path noted earlier
$ mcd i:
$ sudo mlabel -s i:   # display current label
$ sudo mlabel i:foo-bar   # change label to foo-bar
$ sudo mlabel -s i:   # check label

Alternatives

Choosing an alternative

% sudo update-alternatives --config <name>

...where <name> is the name of a symlink in /etc/alternatives. Some of the ones I've used:

editor
x-www-browser
java

You are then prompted to select among the various alternatives available. If the desired alternative is not listed, it will have to be installed.

Installing a new editor

wtf is vim.tiny??

sudo update-alternatives --install /usr/bin/editor editor /usr/bin/vi 1

Syndicate content