Bash – How to move a file and change its name without retyping the name and just add the new characters

bashcommand linemvrename

I change too frequently the location of some files generated daily. The thing is that I want to change their names by only adding the new required characters.

What I want is something like this:

$ mv file.csv /home/user/{something}_backup1

So I could see:

$ ls /home/user
file.csv_backup1

What I'm doing now is the simple:

$ mv file.csv /home/user/file.csv_backup1

You could say "don't be lazy and do it that way", the thing is that the real file names have around 25 characters and retyping them is really annoying.

The past given is only an example, it could be a different directory or different new text.

By the way I'm using bash shell

Best Answer

You could use a or function added in your shell rc file :

mymv(){ echo mv "$1" "$2/${1##*/}_$3"; }
mymv file.csv /home/user backup1

remove the echo when tests are done

Related Question