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. :roll:

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. ;)

About these ads

10 Responses to “Looking for one-line solutions”


  1. 1 Bryan 2009/11/01 at 2:07 PM

    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. 2 ShiftPlusOne 2009/11/02 at 9:27 AM

    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. 3 ShiftPlusOne 2009/11/04 at 4:10 AM

    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.

    • 4 quigybo 2009/11/09 at 8:13 AM

      @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. 5 mulenmar 2009/11/04 at 9:36 AM

    # 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.

    • 6 ShiftPlusOne 2009/11/04 at 7:22 PM

      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)”

      • 7 mulenmar 2009/11/05 at 5:22 AM

        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.


  1. 1 Name a renamer « Motho ke motho ka botho Trackback on 2009/11/08 at 10:02 PM
  2. 2 Convert audio files recursively « Motho ke motho ka botho Trackback on 2010/01/18 at 9:05 AM
  3. 3 A simple batch encryption loop « Motho ke motho ka botho Trackback on 2010/02/05 at 10:04 AM

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s




Welcome!



Visit the Wiki!

Some recent desktops


May 6, 2011
Musca 0.9.24 on Crux Linux
150Mhz Pentium 96Mb 8Gb CF
 


May 14, 2011
IceWM 1.2.37 and Arch Linux
L2300 core duo 3Gb 320Gb

Some recent games


Apr. 21, 2011
Oolite on Xubuntu 11.04
L2300 core duo 3Gb 320Gb

Enter your email address to subscribe to this blog and receive notifications of new posts.

Join 405 other followers

License

This work is licensed under the GNU Free Documentation License. Please see the About page for details.

Blog Stats

  • 3,963,645 hits

Archives


Follow

Get every new post delivered to your Inbox.

Join 405 other followers

%d bloggers like this: