Hey, I'm needing help renaming all the files in a directory. I have a lot of pictures in a lot f different folders that are named 01.jpg 02.jpg, etc. and I want to move them all into one folder. There in lies the problem. The files all need to be renamed, or over written. I have a lot of files to rename if I do it by hand and I hoped that you may have a better idea for me to try.
I'm running Slack 11, with the bare.i 2.4 kernal.
What I'm trying to do is just like .. mv /file/dir/01.jpg /file/dir/prefix_01.jpg but with everythig in the file. Would this work:
mv /file/dir/*.jpg /file/dir/prefix_*.jpg ?
A generic re-name program is "rename". I don't know how to use it, but Newby does, or you can check the manpage.
Alternatively, in this situation, you can do this:
for i in *.jpg; do mv "$i" "prefix_$i"; done
Replace "*.jpg" with any pattern matching your files. Even "*" works.
I tried that, and it says: mv: cannot stat `.JPG': No such file or directory
lamer@kompooter:~/torrents/AMETHYST$ ls
01.JPG 07.JPG 13.JPG 19.JPG 25.JPG 31.JPG 37.JPG 43.JPG 49.JPG
02.JPG 08.JPG 14.JPG 20.JPG 26.JPG 32.JPG 38.JPG 44.JPG 50.JPG
03.JPG 09.JPG 15.JPG 21.JPG 27.JPG 33.JPG 39.JPG 45.JPG 51.JPG
04.JPG 10.JPG 16.JPG 22.JPG 28.JPG 34.JPG 40.JPG 46.JPG 52.JPG
05.JPG 11.JPG 17.JPG 23.JPG 29.JPG 35.JPG 41.JPG 47.JPG THUMBS.DB
06.JPG 12.JPG 18.JPG 24.JPG 30.JPG 36.JPG 42.JPG 48.JPG`
That's one of the dirs, and like, I want it to be "ameth_[picture#].jpg" There's not enough constant besides the .JPG to do the $ with.
Quote$ cd ~/torrents/AMETHYST
$ for i in *.JPG; do mv "$I" "ameth_$I"; done
lamer@kompooter:~/torrents/AMETHYST$ for I in *.JPG; do mv "$I" "ameth_$I"; done
mv: cannot stat `': No such file or directory
lamer@kompooter:~/torrents/AMETHYST$
Edit: It worked once I navigated to the directory with the images in them.. :")