Last active
June 18, 2016 07:00
-
-
Save ralphcrisostomo/b0395a798a799973eeee47a20f1c0394 to your computer and use it in GitHub Desktop.
Script to series on a new created directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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