bash script? how to rename files in random way?
I have a lot of photos that I need to put into a random-order slideshow. Easiest would be to just drag-and-drop the whole lot. Is there any way to scan a directory and batch-rename a group of files into random names, but keeping the extension? (.jpg in this case)
|
Something like:
Code:
for fname in *.jpg rename s/oldpart_of_filename.jpg/newname.jpg/ oldfile.jpg http://www.faqs.org/docs/abs/HTML/ jlinkels PS. I shouodl not have taken taht asty irish Coffee but I hope I gave somathing ti rename files adn not to delterr them all. |
thanks jlinkels, but how do i use this code? I have created a file called ranren.sh and have tried running
Code:
lefty@1[photo_randomized]$ ./ranren.sh thanks for any more help/advice! p.s. I tried Code:
ls | mv * $RANDOM.jpg |
jlinkels forgot to put the $ before fname like this.... $fname. I also put it inside quotes to help with file names that have spaces in them like ---- my latest pic.jpg ----
Also, it's good to have backups in case your code is goofy :) and wouldn't hurt to put an echo before the mv command to give it a test run. Then, remove the echo when it looks good. So, the code may look like this Code:
for fname in *.jpg |
Thanks homey, and you are right about the quotes. And the backups of course.
jlinkels |
that worked! (but I had to run the script twice to affect all of the files-- only the first 119 changed the first round??)
Thank you both for the help and quick responses! lefty.crupps |
random rename - files go missing
hi, using the above
Code:
for fname in *.jpg I have no fix. |
No more filename collisions...
for fname in *.jpg; do mv "$fname" $(echo "$fname" | sha1sum | cut -f1 -d' ').jpg done |
Quote:
|
My two cents...
Quote:
Code:
for i in *.jpg; do mv $i $(echo $i | md5).jpg; done Code:
for i in *.jpg; do mv $i $(openssl rand -rand $i -hex 16).jpg; done |
You should probably note that if all of the pseudo-random numbers happen to be the same, you're going to lose all of your files except for the last one.
|
Quote:
jlinkels |
I only see 11 posts, am I missing something? Hashes don't guarantee no collisions.
|
Nice try.
First you were talking about all pseudo random numbers be the same so all files would be overwritten with the next. Now it was already a low probability that two random numbers are the same. However it was a significant probability, but for two or a few numbers be the same. Not for all numbers being the same. Now you have read the thread and you see a hash was proposed as a solution. And you say that the hash might be the same for different pictures. Sure. The probability is like 1.5 x 10E-29 for a md5 sum collision. Now please state your better solution. jlinkels |
Quote:
Code:
for fname in *.jpg This also has the benefit of still being able to identify the original name for the image. |
All times are GMT -5. The time now is 07:48 PM. |