Cool Shell Tricks

shopt -s cdspell "minor errors in the spelling of a directory
component in a cd command will be corrected"


"Directory stacks"

binary <<< here docs

"single line here docs"
!foo "repeat last command that started with foo"
^find^replace^ "repeat last command, but replace find with
${!tmp_var} "Indirect reference to the contents of the
variable whose name is in tmp_var"

shopt -s nullglob

"Expand failed globs to null"
something with IFS "IFS is the input field separator"
OPTION=${OPTION:-"default"} "Default values in variable expansions."
[[ expr ]] "Double-bracket: Do what I mean!"
(if in zsh)
cd build/arch1/foo

cd arch1 arch2
"will search and replace on current directory
then switch to new directory"

Music on Linux

Music On Linux

by Benjamin McMillan

An introduction to various sound architectures, sound servers, audio codecs, audio
rippers, audio encoders, audio players, and finally, music managers for primarily

Sound Frameworks / Architectures

The most common audio architecture for Linux is
. You can now find ALSA as
a part of the 2.6 Linux kernel, whereas for 2.4 you have to get and download it
separately. ALSA basically provides the drivers necessary for communicating with
your sound hardware (sound cards).

Before ALSA was OSS. It is generally
considered deprecated/obsolete due to ALSA, although ALSA does provide an OSS
compatibility (emulation) layer.

GStreamer is a multimedia framework, which sits on top of ALSA/OSS and provides a
nice interface for creating audio and video players, editors, streamers, and more. It
is usually associated with GNOME, although GNOME is not a prerequisite for using
GStreamer. GStreamer can communicate with various sound servers (like, most notably,
aRTSd). Remember, GStreamer is not a sound server, it is a framework. Totem is a
popular GTK/GNOME media player for audio and video that uses GStreamer (unless you
tell it not to – it can use xine libraries).

Sound Servers

ESD was originally
developed as a part of the Enlightenment project (hence the name), but is now part of
GNOME. ESD supports mixing of different audio simultaneously and network
transparency, as well as being great for sound effects. The mixing, however, is not
necessary for emu10k1 based sound cards (SB Live, Audigy) since they can do it in

“esound is junk. The only thing esd has is a good client API
for going boing at approximately the right time. Anything else
is beyond it.” – Alan Cox

KDE users will probably want to use aRTs. Some say it is better than
ESD in some ways, although development and support is supposedly fading, in favor of
JACK (below).

“was created as an implementation of the Linux Audio Applications
Glue API project, which aimed at creating a high-bandwidth, low-latency
inter-application communication API. It is a real-time sound server written for POSIX
systems (and actually available for Linux and OS X) that enables different
applications to have synchronous connections to the audio hardware and to share audio
among themselves via a ports system. Programs can run as normal independent
applications or as plugins within the JACK server. It … is, in [Vincenot’s] humble opinion, the most excellent and
promising sound server. The only bad point is that it is not widely available at the
moment, but that should be fixed soon” (Christian Vincenot [link]).

Audio Codecs

The original “raw” format for computer/digital audio was WAV (more specifically PCM
WAV), developed by Microsoft (hey, they actually did something useful for once) and IBM.
This format can be read by most operating systems (especially since it is so old),
and is usually the format from which most music is compressed (see below). WAV
itself is lossless, like FLAC, Lossless AAC, and TTA, but those are ways to compress
WAVs into a smaller size (like zip for music, sorta).

This isn’t a codec, but I put it in this section anyway (oh, and neither was WAV).
MPEG-4 is another part of the MPEG standards, made as an improvement over MPEG-1 and
MPEG-2, and is generally used for special Audio CDs and TV (although MPEG-2 is also for TV).
MPEG-4 introduced support for DRM (grrrrr). See below for MPEG-4 AAC.

The most popular and most common is MP3.
This should not be confused with MPEG-3 (which was designed for HDTV, although not
used for such). Unfortunately, MP3 wasn’t free – Fraunhofer required users to pay for
licensing the algorithm. I think this has expired as of recently, although I don’t
know and don’t care (see below for Ogg Vorbis). It is one of the first (early 1990s)
lossy compression formats for audio, and supports frequencies from 16-48 kHz. Most
people like it (because they don’t know any better, or they have old music portables
that don’t support anything else, or they don’t care). See below for better formats.

And then there’s Ogg Vorbis. Ogg is a
nice open source (free) container project for multimedia, and current people use it
to “contain” music files compressed using Vorbis. Vorbis is better than MP3, in that
for a particular file size, a file compressed using Vorbis sounds better than MP3. It
comparable to MPEG-4 AAC. Ogg Vorbis (or anything from the Ogg project) is completely
free and open source, unlike MP3 and other formats. Ogg Vorbis uses a quality metric
(from -1 to 10) instead of bitrates. Quality 0 has an average of 64kbps, 5 is about
160kbps, 6 provides lossless stereo coupling, and 10 is about 400kbps. Ogg Vorbis is not lossless, but
the Ogg project does have FLAC, which is lossless. Many people like to archive their
legally bought music CDs in FLAC, and convert to Ogg Vorbis whenever needed (to put
on a nice iRiver HP portable music player, for instance :)). Ogg Vorbis and FLAC
rock and are the most awesomest things since electricity and women.

AAC is another lossy codec
originally intended for streams, but is most popular with Apple users (because of the
iTunes music store distributing everything as AAC). It is regarded as sounding pretty
darn good (again, comparable to Ogg Vorbis). There is one AAC format designed from
MPEG-2 part 7, and one for MPEG-4 part 3. MPEG-4 is the one that I was referring to
above, and is most popular. It supports a much wider range of frequencies than MP3.
Unfortunately, most MPEG-4 AAC files are plagued with the evil DRM called FairPlay. I
have not successfully played DRM contaminated music on Linux, but I hear others have.

Linux supports the Windows Media Audio (WMA) format, but DRM usually gets in the way.
And WMA sucks (naturally). I hear every time someone uses WMA, somewhere in the world
a dozen kittens die a most horrible death. Save the kittens, don’t use WMA (don’t you
just love the lack of bias in this article!?).

Audio Rippers

CDDA Paranoia is an application for
extracting audio content from CDs and saving as (typically) PCM WAV. Very popular,
but command line. See below for frontends. There’s also cdda2wav. I don’t use it,

GRIP screenshot

And then we have frontends! I like grip,
which is both a cd-player and (most notably) a ripper and encoder for GNOME. It has
cdparanoia bultin, but can use external rippers (like an external cdparanoia binary,
or cdda2wav). It is multithreaded and can encode music as well (using any encoder you
wish, like for mp3 or ogg). The neat thing about it is, it can rip and encode at the
same time (staggered of course).

KDE users can either use KAudioCreater or Konqueror to rip CDs. Konqueror can
supposedly also encode after ripping. I am not familiar with these methods, but
hopefully someone in the audience is and can explain 🙂 Here
is an article about

using Konqueror for this task, thanks to Google Cache. And this just in, k3b will
also rip to WAV.

Audio Encoders

See grip (above).

Several MP3 encoders are available – notably, lame and blade. I haven’t used an mp3
encoder for a very long time, but I found on one of the internets a site comparing
the outputs of each. They say lame is better at low bitrates, and blade at high.
Clicky Clicky.

And of course there’s an encoder for Ogg Vorbis called oggenc. As I mentioned above,
Ogg Vorbis uses a quality metric from -1 to 10, so you will need to specify the
setting you desire using the -q argument to oggenc. Below is an example call for
oggenc (read the man pages for more info):

$> oggenc -q 6.8 -d 2004 -N Track# -t “Song” -l “Album” -a “Artist” -G “Genre” -o /path/to/new/file.ogg /path/to/wav/file.wav

The encoder for FLAC is called “flac.” You specify compressions levels through FLAC,
where level 0 is fast (alias –fast) and 8 is best (–best). You can also specify
sample rate, endianess, bits per sample, and more as you would expect. Metadata
comments are added using the -T argument (-T ARTIST=”U2″ -T ALBUM=”Jacob Tree” …).

Audio Players

XMMS is probably the most popular linux music
player. Unfortunately, it is old and the development speed comparable to Debian. It
has many cool plugins for visualizations and codec support, and can use alsa/oss
directly or use a sound daemon. I believe gstreamer will also work. Also
unfortunately, it uses GTK 1.2.

Which brings us to Beep. It
is a fork of XMMS, but uses GTK 2 so it looks a lot better. And development isn’t at
a standstill.

Rhythmbox is a nice, iTunes-like music player
and management system for GNOME. It’s really nice, I use it. And since it is meant
for GNOME, it users GStreamer. Rhythmbox also supports internet radio.

amaroK is a nice music player and manager for
KDE. I have only used it for a minute or two, but it seems to be nice and supports
basically what Rhythmbox does.

KDE also has JuK. Seems
pretty advanced, supports a lot of cool stuff. Probably your best bet for KDE users.

Music Managers

Rhythmbox and amaroK are music managers as well as players, which are mentioned

Netjuke is a nice web application in
PHP4 that serves as sort of a portal for your music collection. It is multiuser,
where each user can have private and public/shareable playlists – but of whatever
music is in the repository. The backend is mysql – you basically import a directory
of music into the database through the web application. It supports searching and
browsing, the the front page has a nice display of recent additions. You can either
use it locally to manage and play your music (by downloading a playlist file which
can be opened in your favorite player) or remotely if your webserver can access the
actual files for distribution/streaming.


AudioScrobbler is a nice service for building a profile of your music taste via a
plugin and offers statistics as well as recommendations. Quite a few apps have
plugins available to do this.

FreeDB is a free CDDB service for downloading album information. Apps like grip
use it to automatically populate metadata so you don’t have to. Sometimes, though,
you will need to fix or modify what you get.

MusicBrainz is a community music metadatabase like
FreeDB. I don’t know much more than that.

And I hear the newest version of CrossOver (commercial unfree wine) supports iTunes.

Misc External Links