Created
September 6, 2020 18:34
-
-
Save markbosky/2e58d840f147c59d6508a64af701b6d4 to your computer and use it in GitHub Desktop.
Rename files within a directory to random strings (don't forget to chmod 755 to execute)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| chars=( {a..z} {A..Z} {0..9} ) | |
| function rand_string { | |
| local c=$1 ret= | |
| while((c--)); do | |
| ret+=${chars[$((RANDOM%${#chars[@]}))]} | |
| done | |
| printf '%s\n' "$ret" | |
| } | |
| for file in ~/PictureDir* | |
| do | |
| ext=$(echo ${file} | sed 's,^.*\(\.[^\.]*$\),\1,') | |
| mv "$file" ~PicturesDirRenamed/"$(rand_string 10)"${ext} | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment