Skip to content

Instantly share code, notes, and snippets.

@pasdam
Created January 1, 2023 17:55
Show Gist options
  • Save pasdam/b307b73af17fade880ecd3098b30c3fa to your computer and use it in GitHub Desktop.
Save pasdam/b307b73af17fade880ecd3098b30c3fa to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
DIR=$1
cd "$DIR"
for d in */ ; do
if [[ "$d" =~ .*\([0-9\-]+\).* ]]; then
date=$(echo $d | sed "s/.*(//" | sed "s/)\///")
new_name="$date - $(echo $d | sed "s/$date//" | sed "s/ ()//")"
if [ ! -d "$new_name" ]; then
mv "$d" "$new_name"
else
echo "Skipping $d as $new_name already exists"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment