Looking for one-line solutions

I try to collect as many practical and functional command-line applications as I can. And yet more and more frequently, it seems that much of what I want to get done doesn’t need an actual “application.”

As an example, I recently (and once or twice before, in the past) needed to convert between audio file formats, mostly because I prefer ogg files, but also just because m4a support is more work than it’s worth. 🙄

Each time it becomes important I make a quick run through the Internet, looking for something that looks like a comprehensive, console-based application that can convert between audio formats. And every time, the Internet spits out a page with this on it.

for nam in *.mp4; do nice mplayer -ao pcm "$nam" -ao pcm:file="$nam.wav" && nice oggenc -q5 "$nam.wav" -o "$(basename "$nam" .mp4).ogg"; rm "$nam.wav"; done

As you see it, it’s not really going to do the job, but with a few small adjustments — change the file type at first, and maybe the quality level — it suddenly becomes the perfect audio file converter. With mplayer and vorbis-tools already on board, it requires no extra dependencies, no obscure libraries and no more effort than it takes to copy that line into the terminal.

And the results are indistinguishable from what I might get from any “application” that’s out there. Of course, I have to admit, after finding that one-line solution, I didn’t look around much longer. 😉


10 thoughts on “Looking for one-line solutions

  1. Bryan

    One of my favorite one-liners is the one I use to sync my iPod with my music directory. Since I use Rockbox, this is rather universal (just ensure that your media device has a persistent mountpoint):

    rsync -avW –progress –size-only –delete ~/music/* /media/iPod

    Note that this performs a ‘real’ sync to the folder on your harddrive.(i.e it deletes a file if it is on your media device, but not your harddrive) It’s also probably rather inefficient, since the -W flag tells rsync to copy the whole file rather than use it’s delta algorithm to only move what’s changed. This doesn’t bother me though, since I rarely (if ever..) update a song once it’s in place.

  2. ShiftPlusOne

    I am not good at bash scripting and I am sure most people would go about this a different way. Here’s how I zero-write the free space on a disk 5 times. Since laptops get stolen I don’t want stuff I had on there (essays, photos, illegal software and so on) to be recoverable.

    COUNTER=0 ; while [ $COUNTER -lt 5 ] ; do let COUNTER=COUNTER+1;dd if=/dev/zero of=zero; rm zero; done;

  3. ShiftPlusOne

    When working with files with numbers you can always (starting from bash 3)
    use {1..100) or use something like {a..z} for letters… helps in the 1 line department.

    1. quigybo

      @ShiftPlusOne: One thing I found out recently that also rocks, you can do {001..100} to make it pad with zeros. Extremely useful at times.

      @kmandla: Cheers for the command, I actually needed it a few days ago. Perfect timing.

  4. mulenmar

    # mount /dev/sda1 /mnt -o noatime && rm /mnt/Windows/* -rf

    solved my Vista problem from a Linux-based live-cd. :mrgreen:

    Also, this helps nicely on my Dell Latitude:

    $ nice -n 15 midori

    For those who don’t know, and if I understand it correctly, it makes the kernel schedule more processor time to the designated program (in this case the Midori web browser) and any programs started by it.

    1. ShiftPlusOne

      I think the higher the ‘niceness’ the less processor time is allocated… from man nice:
      “Nicenesses range from -20 (most favorable scheduling) to 19 (least favorable)”

      1. mulenmar

        Oh yes, stupid mistake on my part. :blush: However, it does seem to help to increase the nice value sometimes. Perhaps it’s just a psychological thing, I don’t know.

  5. Pingback: Name a renamer « Motho ke motho ka botho

  6. Pingback: Convert audio files recursively « Motho ke motho ka botho

  7. Pingback: A simple batch encryption loop « Motho ke motho ka botho

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s