Renaming Multiple Files in SSH

Status
Not open for further replies.

Crucify

Active Member
606
2009
1
0
need a little help with renaming multiple files....

I can batch rename files to add Prefixes or replace blank spaces to underscores...
but what I am unable to do is to add suffixes to all the files in a directory

I have files such as
filename.rar
filename2.rar
filename3.rar

I want to add suffix like this..
filename_[sitename].rar
filename2_[sitename].rar
filename3_[sitename].rar


any help or clue is really appreciated
 
6 comments
Suffix
Code:
for i in *.rar; do mv "$i" "`basename $i .rar`_[sitename].rar"; done

Prefix
Code:
find *.rar -exec mv {} [sitename]_{} \;

Hope that helps. :)
 
for prefixing i use

Code:
for i in * ; do mv $i [sitename]_${i#} ; done

but your one's working too...


unfortunately the suffix is still not working...when executed it shows...

mv: cannot stat `\223102-AF.rar\224': No such file or directory

any idea why?
 
The suffix code looks like it's trying to add a suffix after the .rar extension and adding a .rar to the entire file name after the suffix.

No idea though, on why the rename fails. I haven't tried it.
 
No idea why it wont work, this is the result I get;

cd test
ls
filename.rar filename2.rar filename3.rar
for i in *.rar; do mv "$i" "`basename $i .rar`_[sitename].rar"; done
ls
filename_[sitename].rar filename3_[sitename].rar filename2_[sitename].rar
 
Sorry about the double post, just wanted to bump this to make it abundantly clear...


I made a silly typo :P Sorry about that CrucifynDi3, heh

Suffix
Code:
for i in *.rar; do mv "$i" "`basename $i .rar`_[sitename].rar"; done

EDIT: Updated all my posts so if someone stumbles across this thread it wont cause confusion.

Hope that helps. :)

The suffix code looks like it's trying to add a suffix after the .rar extension and adding a .rar to the entire file name after the suffix.
It just renames each file by removing the .rar, then it renaming the file it to _[sitename].rar.
Just a bit more complicated than a prefix because it needs to hold the file name before temporarily in memory.
 
yess, that works perfect Juo! :D
after so many days a working solution lol.

btw, just out of curiousity, which part removes the .rar? im assuming its $i .rar?

Anywayz, thanx to both Juo for the code and also to lifetalk for the alternative solution you gave thru PM.
 
Status
Not open for further replies.
Back
Top