#!/bin/bash # Find directories in the current directory and process each one find . -maxdepth 1 -type d -print0 | while IFS= read -r -d '' dir; do if [[ "$dir" != "." ]]; then # Extract the old directory name, stripping leading './' OLDNAME="${dir:2}" echo "==== $OLDNAME ====" # Generate the new directory name NEWNAME=$(echo "$OLDNAME" | awk -F'시즌[0-9]' '{ print $1 }') if [[ "$OLDNAME" == "$NEWNAME" ]]; then echo "\"$OLDNAME\" ok!" else echo "\"$OLDNAME\" -> \"$NEWNAME\"" # Ensure the new directory does not already exist to avoid overwriting if [[ ! -d "$NEWNAME" ]]; then sudo mkdir "$NEWNAME" sudo mv "$dir" "$NEWNAME" else echo "\"$NEWNAME\" already exists, skipping move $OLDNAME" fi fi fi done