Skip to content

Instantly share code, notes, and snippets.

@archfizz
Created April 14, 2013 11:16
Show Gist options
  • Save archfizz/5382336 to your computer and use it in GitHub Desktop.
Save archfizz/5382336 to your computer and use it in GitHub Desktop.
Remove file extension from one file or from all files in working directory
## To remove a file extension from a given file
## Load the following function
rmext () {
if test -f "$1"
then
F=$1
E=${F#*.}
mv $1 `basename $1 .$E`;
fi
}
# Then use based on these given examples
#
# rmext mixset.mp3
# rmext lastnightsparty.jpg
# -------------------------
## To Remove a file extension from all files in the current working directory
## Load the following function
rmextdir () {
for i in *
do
if test -f "$i"
then
mv $i `basename $i .$1`;
fi
done
}
# Then use based on these given examples
#
# rmextdir mp3
# rmextdir jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment