I have a script that randomizes filenames with the JPEG extension:
#!/bin/bash for img in *.jpg; do newname=$(head /dev/urandom | tr -dc a-z0-9 | head -c 8) mv "$img" "$newname".jpg; done
This script, when used with JPEG files, outputs filenames such as the following:
0cb1v984.jpg dqm2xxoj.jpg o61bg4n5.jpg
However, when I try to replace the ".jpg" extension in this bash script with ".gif" or ".webp" it doesn't work.
Is the problem due to the GIFs and WEBPs I'm attempting to rename being animated GIFs and WEBPs?
Ideally I'd like one bash script that can randomize the filenames of files with any of these 3 extensions, but I'd be fine to have 3 different bash scripts to randomize the filenames of each extension.
I've fiddled around with the most upvoted answer to this question, to no avail.
tempfile
command can create arbitrary files in a user-determined directory and with a user-determined prefix and suffix. Perhaps you could capture the name and move your file to it. – MDeBusk Aug 10 '22 at 19:35jpg
in your onliner when trying a different filetype? – Panki Aug 10 '22 at 19:37