Command Line – Create Backup Copy of File Without Typing Name Twice

command linecp

Often when I'm editing some system file first I create a backup copy. For example:

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

Is there any simple 'shortcut' such as:

sudo cp /etc/ssh/sshd_config %s.bak


A workaround that I found is to use sed in this way:

sudo sed '' /etc/ssh/sshd_config -i.bak

Best Answer

You could use brace expansion like this:

cp example_file{,.bak}