com reanomenar fitxers en massa
Un exemple de com utilitzar la línia d'ordres per estalviar feina
i temps.
Tenim un directori amb aquests fitxers:
ernest@tty2:~/cdrw/harvey/06-uh-huh-her $ ls
pj harvey - cat on the wall.mp3 pj harvey - the end.mp3
pj harvey - it's you.mp3 pj harvey - the letter.mp3
pj harvey - no child of mine.mp3 pj harvey - the life & death of mr. badmouth.mp3
pj harvey - pocket knife.mp3 pj harvey - the slow drug.mp3
pj harvey - seagulls.mp3 pj harvey - who the fuck?.mp3
pj harvey - shame.mp3 pj harvey - you come through.mp3
pj harvey - the darker days of me and him.mp3 uh huh her.m3u
pj harvey - the desperate kingdom of love.mp3
El fitxer "uh huh her.m3u" és una llista ordenada de totes les
cançons (un fitxer per línia), estil "playlist" del xmms. Ara el
que vull fer és canviar el nom dels fitxers per afegir-los un
número (pq el reproductor de MP3 que tinc només reprodueix per
ordre alfabètic). Ho podria fer a mà. Però millor això:
num=0; cat *.m3u | while read line; do
mv "$line" "`if [ $num -lt 10 ]; then echo 0; fi`$num-`echo $line|cut -d ' ' -f 4-`"
let num++
done
I el resultat és el següent:
ernest@tty2:~/cdrw/harvey/06-uh-huh-her $ ls
00-the life & death of mr. badmouth.mp3 05-the slow drug.mp3 10-the end.mp3
01-shame.mp3 06-no child of mine.mp3 11-the desperate kingdom of love.mp3
02-who the fuck?.mp3 07-cat on the wall.mp3 12-seagulls.mp3
03-pocket knife.mp3 08-you come through.mp3 13-the darker days of me and him.mp3
04-the letter.mp3 09-it's you.mp3 uh huh her.m3u
He de dir que m'ha sortit a la primera :)))
Llavors només falta:
ls *.mp3 > uh\ huh\ her.m3u
I llestos.
--
ernest
That's all you need tae dae in life. Just be yourself, he'd tell me.
It was the most difficult, challenging thing anybody ever asked of me.
--Irvine Welsh, Glue.
Reply to: