May 24, 2009

Bluk rename files in Linux

Today one of my friend asked me to bulk rename all files in a folder. He had a collection of songs named randomly with no extension. He also wanted to add the extension, mp3 in all files(Yes, he was sure about the encoding)
I opened a terminal in that folder and executed the following command.
NUM=1
for SONG in ./*
do
mv $SONG song$NUM.mp3
let NUM=NUM+1
done

So lets peek what the above script does:
  1. Defined a variable NUM and initialized it with 1.
  2. Defined a foreach loop. Here for each files in current path the for loop is executed.
  3. Rename(move) the file $SONG to song<num>.mp3
  4. Increase the value of variable NUM by 1.
  5. end. ;)
So if you want to rename in a different fashion you can hack the line mv $SONG song$NUM.mp3 in any way you like. But Remember the second argument to the mv command must vary for each loop, otherwise you will end up deleting all files except the last one.

May 11, 2009

Solve no sound problem in Ubuntu

One after another 17 days have passed.. till today my laptop was completely silent when i booted into Ubuntu. But now, just 10 mins back, after a lot of hit and trial with driver model, I could make make my laptop speak. Here's what I did.
Though I specified this as ubuntu problem in title, it the problem of alsa; it's not recognizing your device.

I completely forgot what I did to mess up my laptop-sound-system, so i thought to start afresh.
I removed the alsa and pulseaudio completely. And One thing I would like to mention: I am completely unfamiliar about the interaction of alsa and pulseaudio with the sound system. This is my first deal with sound system of linux to this depth.
sudo apt-get --purge remove linux-sound-base alsa-base alsa-utils \
"pulseaudio-*"

Then I did a quick Reboot; just playing safe. (Jaunty boots on/off so fast, I am fan of it.)
Next I reinstalled the alsa with pulseaudio.
sudo apt-get install linux-sound-base alsa-base alsa-utils \
libasound2-plugins "pulseaudio-*" paman padevchooser \
paprefs pavucontrol pavumeter

Then, I appended following lines to the file /etc/modprobe.d/alsa-base.conf
alias snd-card-0 snd-hda-intel
alias sound-slot-0 snd-hda-intel
options snd-hda-intel model=dell-m6
options snd-hda-intel enable_msi=1

The bold faced "model=dell-m6" was the main hack for the system to work.

Then after another quick boot, I got the sound.

During this I refered a lot of pages, But the most useful and the one that is well documented is: Comprehensive Sound Problem Solutions Guide
And this is the page where I got the model of the sound-card(dell-m6) from.