[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Using stupid filenames in shell scripts



> If you are going to produce new mp3's, you will consider naming them without 
> spaces. Just replace all spaces with underscores _ . If you want to know how 
> to rename all existing files, wait for Colin Watson to answer, he is 
> something like the "script guru" over here. Maybe he will also explain how 
> quoting works in bash, I have read the man page, but I still don't understand 
> it :(

Here's what I would do:

for x in *mp3; do mv "$x" ${x// /_}; done;

(turns spaces to underscores)

If you actually have double quotes in any your filenames, this won't
quite work.

Personally, I would also set everything lowercase:

for x in *; do mv "$x" `echo $x | tr "A-Z " "a-z_"`; done;

(also turns spaces to underscores)

You might consider changing "mv" to "echo" before actually running it, to
see what will happen, or creating a backup copy of your files just in
case.
---
Adam Kessel (adam@bostoncoop.net)

On Thu, May 15, 2003 at 04:13:27PM +0200, Joerg Johannes wrote:
> > When I want to do anything useful with these files, I'd like to use a
> > script to avoid repeating the same action say 15 times.
> > For instance, I'd use something like:
> > for i in `ls`; do echo $i; done
> > This doesn't work properly. $i gets a lot of values like 01, -,
> > Artist, Song.mp3 instead of one value per file.
> You have to put the $i in double-quotes. The right script is
> for i in *.mp3; do echo $i; done
> Also, 
> mpg123 *.mp3
> should work...

Attachment: pgpau3WBrasDP.pgp
Description: PGP signature


Reply to: