Renaming files
I have several image files that are named
147.jpg 148.jpg 149.jpg I need to rename all the files to look like the following img147.jpg img148.jpg img149.jpg I am having trouble writing this simple script. Any help would be greatly appreciated. Pierre |
try:
Quote:
|
i tried the script. I made it executable and this is what I see: call: rename from to files...
the files were not renamed. where did i go wrong? I made the file executable by using chmod u+x rename I named the file rename |
Make sure you issue the command in the directory where the files are. The script itself needs to be either in the same directory or make sure it's included in your $PATH variable.
Code:
[xtd8865@localhost lopa]$ ls Code:
[xtd8865@localhost lopa]$ cat myscript |
if you have the rename command on your system just use that.
the syntax is rename from to files Code:
rename 1 img1 ./*.jpg you can use it to do all sorts of interesting things if you want to include spaces use quotes Code:
rename "a song" "a great song" *.mp3 i have found it useful anyways |
Viablade,
It seems that by naming your script 'rename' you tried to use /usr/bin/rename command. You need to either run your script with full path (or just ./rename if you are in this dir) or just RENAME your 'rename' script :) (I mean, change it's name..) |
cyprinidae's right
when you run rename your actually running the command that i mentioned. Quote:
|
ya just run
Code:
mv ./rename myscript Code:
./myscript |
if you have Python, you can use the script in my sig called File Renamer
eg usage Code:
# filerenamer.py -i "img" -l "*.jpg" |
I really wouldn't bother writing such a simple script, it's less time consuming (and less prone to problems like the one that arose) to just do "for i in *.jpg; do echo mv "$i" "img$i"; done", if you like the results, remove the "echo" to apply the changes.
|
i finally got it to work. I also needed to change the extension from .JPG to .jpg. I tried this
#!/bin/bash for filename in * do echo "mv -v ${filename} ${filename}.jpg" # mv -v ${filename} ${filename}.jpg done This changed my files to filename.JPG.jpg instead of filename.jpg |
Code:
#!/bin/bash |
All times are GMT -5. The time now is 02:16 PM. |