Skip to content

Instantly share code, notes, and snippets.

@ralphcrisostomo ralphcrisostomo/move.sh
Last active Jun 18, 2016

Embed
What would you like to do?
Script to series on a new created directory
#!/bin/bash
# Script to series on a new created directory
# By Ralph Crisostomo - 2016.04.17
#
# Usage :
# sudo ./move.sh SU supergirl Series01
#
PATTERN=$1
NAME=$2
echo "---------"
echo "Moving files : "
echo "---------"
while IFS= read -d '' -r ITEM; do echo $ITEM; done< <(find "$PWD" \( -iname "$PATTERN*.avi" -or -iname "$PATTERN*.mkv" -or -iname "$PATTERN*.mp4" -or -iname "$PATTERN*.srt" \) -print0)
echo "---------"
while IFS= read -d '' -r ITEM
do
# Set season
if [[ $ITEM =~ S[[:digit:]]{2} ]]; then SEASON=${BASH_REMATCH}; fi
MEDIA="/media/$3/_new"
DESTINATION="$MEDIA/$NAME/$SEASON"
# Create directory
[[ -d $DESTINATION ]] || mkdir -p $DESTINATION
# Copy files
rsync -av -P "$ITEM" "$DESTINATION"
done< <(find "$PWD" \( -iname "$PATTERN*.avi" -or -iname "$PATTERN*.mkv" -or -iname "$PATTERN*.mp4" -or -iname "$PATTERN*.srt" \) -print0)
echo "---------"
echo "Deleting files : "
echo "---------"
while IFS= read -d '' -r ITEM; do rm -rfv "$ITEM"; done< <(find "$PWD" -iname "$PATTERN*" -print0)
echo "---------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.