Skip to content

Instantly share code, notes, and snippets.

@markbosky
Created September 6, 2020 18:34
Show Gist options
  • Select an option

  • Save markbosky/2e58d840f147c59d6508a64af701b6d4 to your computer and use it in GitHub Desktop.

Select an option

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)
#!/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