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?
Asked
Active
Viewed 516 times
0
-
Looks a lot like a homework task. – David Oct 01 '21 at 11:42
-
Interesting task nevertheless ;-) – pLumo Oct 01 '21 at 13:22
1 Answers
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 withrename
. - 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