Skip to content

Instantly share code, notes, and snippets.

@niladam
Forked from premek/mv.sh
Created April 19, 2020 12:22
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 niladam/0dda8660cdd3c11081e0b236c6316184 to your computer and use it in GitHub Desktop.
Save niladam/0dda8660cdd3c11081e0b236c6316184 to your computer and use it in GitHub Desktop.
Rename files in linux / bash using mv command without typing the full name two times
# Put this function to your .bashrc file.
# Usage: mv oldfilename
# If you call mv without the second parameter it will prompt you to edit the filename on command line.
# Original mv is called when it's called with more than one argument.
# It's useful when you want to change just a few letters in a long name.
#
# Also see:
# - imv from renameutils
# - Ctrl-W Ctrl-Y Ctrl-Y (cut last word, paste, paste)
function mv() {
if [ "$#" -ne 1 ] || [ ! -e "$1" ]; then
command mv "$@"
return
fi
read -ei "$1" newfilename
command mv -v -- "$1" "$newfilename"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment