LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help in renameing files in terminal (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-in-renameing-files-in-terminal-608216/)

bookman761 12-20-2007 04:44 PM

Need help in renameing files in terminal
 
Hi,

I have a collection of mp3 files that I would like to rename. I want to simply add a prefis to my files such as;

hotel california.mp3 >>>>> eagles-hotel california.mp3

Do you knoe the rename command and its options to do this in the terminal?

Thanks,
FG

pwc101 12-20-2007 04:49 PM

Code:

mv hotel\ california.mp3 eagles-hotel\ california.mp3
You need to escape the spaces with a backslash. Otherwise, you could do this:
Code:

mv "hotel california.mp3" "eagles-hotel california.mp3"

bookman761 12-20-2007 04:51 PM

How do i do this to multiple files at once.

Do I simply do:


mv *.mp3 eagles-*.mp3

Thanks,

FG

lleb 12-20-2007 05:14 PM

there is a way, but i forget it has to do with building a string $ and changing things.

gilead 12-20-2007 05:18 PM

Do you have the rename command in your distro? From the man page:
Code:

rename  will  rename  the specified files by replacing the first
occurrence of from in their name by to.

For example, given the files foo1, ..., foo9, foo10, ..., foo278, the commands

              rename foo foo0 foo?
              rename foo foo0 foo??

will turn them into foo001, ..., foo009, foo010, ..., foo278.

And
              rename .htm .html *.htm

will fix the extension of your html files.


chrism01 12-20-2007 05:24 PM

FYI, most Unix tools don't like spaces in filenames, so you have to either explicitly escape them or use quotes as mentioned above.
In short, don't put spaces in filenames if you can avoid it.

dasy2k1 12-20-2007 08:16 PM

Quote:

Originally Posted by bookman761 (Post 2997471)
How do i do this to multiple files at once.

Do I simply do:


mv *.mp3 eagles-*.mp3

Thanks,

FG

should work.

though the spaces may cause problems

gilead 12-21-2007 12:35 AM

Quote:

Originally Posted by dasy2k1 (Post 2997613)
Code:

mv *.mp3 eagles-*.mp3
should work.

though the spaces may cause problems

No, that doesn't work here. The shell tried to expand each '*' before passing it to the mv command. The eagles-*.mp3 couldn't be expanded, was passed to mv as the destination directory and caused an error of:
Code:

mv: target `eagles-*.mp3' is not a directory

pwc101 12-21-2007 05:01 AM

Quote:

Originally Posted by bookman761 (Post 2997471)
How do i do this to multiple files at once.

Do I simply do:


mv *.mp3 eagles-*.mp3

Thanks,

FG

This should do it:
Code:

for i in *.mp3; do mv "$i" eagles-"$i"; done


All times are GMT -5. The time now is 10:44 AM.