Skip to content

Instantly share code, notes, and snippets.

@kadin2048
Created January 14, 2015 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadin2048/5aa29d0691f3b4400863 to your computer and use it in GitHub Desktop.
Save kadin2048/5aa29d0691f3b4400863 to your computer and use it in GitHub Desktop.
Renames files that have the same basename but different extensions, e.g. 'somefile.avi', 'somefile.nfo', 'somefile.txt' to 'anotherfile.avi', 'anotherfile.nfo', etc.
#!/bin/sh
# From http://stackoverflow.com/questions/15585441/batch-renaming-multiple-files-with-different-extensions-linux-script
# first argument - basename of files to be moved
# second arguments - basename of destination files
if [ $# -ne 2 ]; then
echo "Two arguments required."
exit;
fi
#echo "First argument $1"
#echo "Second argument $2"
for i in "$1".*; do
if [ -e "$i" ]; then
mv "$i" "$2.${i##*.}"
echo "$i to $2.${i##*.}";
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment