0

I have a set of .png images, currently named in sequence from 1 to 1000. How can I take these images and reassign them to a random number between 1 & 1000 so I end up with the same range of sequential numbers, but the image under each number is no longer the same?

wes.p
  • 1

1 Answers1

0

Could be done like this:

names=({1..1000}.png)
new_names=($(shuf -e {1..1000}.png.tmp))
for n in "${!names[@]}"; do
    echo mv "${names[$n]}" "${new_names[$n]}"
done && rename -n 's/\.tmp$//' *.tmp
  • Create two arrays $names and $new_names
  • we need to name it .tmp or so to not overwrite existing files, we'll fix this with rename.
  • loop over array keys and run mv for each.

Note: To actually run the command, remove the echo and -n from rename.

pLumo
  • 26,947