Skip to content

Instantly share code, notes, and snippets.

@rothgar
Created March 23, 2012 04:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rothgar/2166713 to your computer and use it in GitHub Desktop.
Save rothgar/2166713 to your computer and use it in GitHub Desktop.
Script for moving movie files
#!/bin/bash
#
# Usage: filestodirs 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
IFS=$'\n'
for file in `ls -1`
do
dirname=`echo "$file" | sed 's/\s([0-9]\+).*//'
filename=`echo "$file" | sed 's/\s([0-9]\+)//'
mkdir "$dirname"
mv "$file" "$dirname"/"$filename"
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment