Last active
October 31, 2016 12:55
-
-
Save koter84/d4fd34eb47756017b888c66a112de707 to your computer and use it in GitHub Desktop.
reverse the filename for the current dir
This file contains 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 | |
if [ "$1" != "" ] | |
then | |
dir=$1 | |
else | |
dir=$GIST_PWD | |
fi | |
cd "$dir" | |
function reverseIt | |
{ | |
file="$1" | |
if [ -d "$file" ]; then # check if it is a dir | |
echo -n "$(rev <<< "${file}")" | |
elif [[ $file == *.* ]]; then # check if there is a . in the file | |
echo -n "$(rev <<< "${file%.*}").${file##*.}" | |
else | |
echo -n "$(rev <<< "${file}")" | |
fi | |
} | |
for file in * | |
do | |
reverser=$(reverseIt "$file") | |
echo "file: $file -> $reverser" | |
done | |
read -p "Is this OK? [y/N] " preview_ok | |
if [ "$preview_ok" == "y" ] || [ "$preview_ok" == "Y" ] | |
then | |
for file in * | |
do | |
reverser=$(reverseIt "$file") | |
mv "$file" "$reverser" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment