Skip to content

Instantly share code, notes, and snippets.

@2jiwon
Last active April 12, 2018 13:54
Show Gist options
  • Save 2jiwon/1dad9a100bb886f8e7dc492ee24070d4 to your computer and use it in GitHub Desktop.
Save 2jiwon/1dad9a100bb886f8e7dc492ee24070d4 to your computer and use it in GitHub Desktop.
A Bash Shell Script to find ".aaa" files recursively in a directory, then rename the files as ".bbb".
#!/bin/bash
num = 0
for file in $(find ./* -name '*.sgk' | grep -n 'sgk$')
do
(( num++ ))
echo "$file"
done
echo -e '\n' "Searched $num files.\n"
answer="N"
echo -n "Is this result right? Do you want to change the file names? (y/N)"
read answer
if [[ "$answer" == [Yy] ]]
then
for file in $(find ./* -name '*.sgk' | grep 'sgk$')
¦ do
¦ ¦ ¦ mv "$file" "${file%.sgk}.php"
¦ done
if [[ $? == "0" ]]; then
¦ echo -e "Done.\n"
fi
else
echo -e "Okay,bye... \n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment