Issue
Assuming an arbitrary number of files with random names and the same file extension (e.g., file1.txt
, file2.txt...fileN.txt
). How could you rename them all reliably with a random string?
Such as, file1.txt, file2.txt...fileN.txt
to asdfwefer.txt, jsdafjk.txt
... or any combination of letters from latin alphabet].txt
Solution
quickest hack to get a random-letters string I can think of is
head -c24 /dev/urandom | base64 | tr -dc a-zA-Z
so
randomname() { head -c24 /dev/urandom | base64 | tr -dc a-zA-Z; }
for f in file*.txt; do mv "$f" `randomname`.txt; done
and your odds of a collision are down in the one-in-a-billion range even with a huge list. Add a serial number on the end of randomname
's output and that goes away too.
Answered By - jthill Answer Checked By - Candace Johnson (WPSolving Volunteer)