Bash script: Randomize filenames in a directory

Continuing on the theme of file management from my last post: This script takes a folder of files and randomizes all filenames, whilst keeping the filename extension. This is useful if you're sorting by name, and want to have the files presented in a random order. Some possible use cases are a folder of pictures you intend to post to a blog, do further processing on, and the order and names of the files aren't important.

Usage: cd to the directory that contains the files you wish to randomize the filenames of, then run the script.

# Randomize file names in current working directory, keeping the filename extension
# Modified from:
# Ignores dotfiles and subdirectories

find . -type f -not -path '*/.*' |
while read -r name; do
  case $ext in
    *.*) ext=.${ext##*.};;
    *) ext=;;
  mv "$name" "$newName$ext"


  1. Markdown is allowed. HTML tags allowed: <strong>, <em>, <blockquote>, <code>, <pre>, <a>.