Skip to content

Instantly share code, notes, and snippets.

@koter84
Last active October 31, 2016 12:55
Show Gist options
  • Save koter84/d4fd34eb47756017b888c66a112de707 to your computer and use it in GitHub Desktop.
Save koter84/d4fd34eb47756017b888c66a112de707 to your computer and use it in GitHub Desktop.
reverse the filename for the current dir
#!/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