Skip to content

Instantly share code, notes, and snippets.

@cmprescott
Last active August 29, 2015 14:12
Show Gist options
  • Save cmprescott/7ec176a03dd5f58419df to your computer and use it in GitHub Desktop.
Save cmprescott/7ec176a03dd5f58419df to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# FILE:
# prepend_random_num.sh
# ABOUT:
# Prepends a random number between 1-65000 and an underscore to all files of specified type
# Runs on Mac OSX & Linux
# EXAMPLE:
# $ ls
# a.jpg b.jpg
# $ sh prepend_random_num.sh jpg
# $ ls
# 138_b.jpg 8474_a.jpg
for file in *.$1
do
rand=$(jot -r 1 1 65000 || shuf -i 1-65000 -n 1)
mv "$file" "$rand"_"$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment