Skip to content

Instantly share code, notes, and snippets.

@aauren
Forked from rothgar/movie_move.sh
Created March 24, 2012 00:00
Show Gist options
  • Save aauren/2176543 to your computer and use it in GitHub Desktop.
Save aauren/2176543 to your computer and use it in GitHub Desktop.
Script for moving movie files
#!/bin/bash
#
# Usage: movie_move.sh directory_name
#
# Moves all files in the specified directory into
# subdirectories of the same name, minus the file
# extension.
if [ $# -ne 1 ]; then
echo "Usage: ./filestodirs directory_name"
exit 1
fi
cd $1
for file in $(ls); do
dest_dirname=$(echo "$file" | sed 's/\s([0-9]\+).*//')
dest_filename=$(echo "$file" | sed 's/\s([0-9]\+)//')
mkdir "${dest_dirname}"
mv "${file}" "${dest_dirname}/${dest_filename}"
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment