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
You could use brace expansion like this:
1. What you asked for
You can create a small shellscript file
bupper
:I have a directory
~/bin
, where I keep such help files.Make it executable,
When in
~/bin
, it will be in PATH and you can run it like any executable program anywhere (where you have write permissions).Example:
2. Alternative - let the editor do the job automatically
Some editors have an option to create a backup copy of the file before you save a new version. This backup has often a tilde as the last character (tilde is the extension, but there is no dot before it).
Gedit, the standard editor in Ubuntu is one of them.
After setting
gedit
to save such a backup copy:And check afterwards
Now
hello.txt~
has been added tohello.txt
and the backup created bybupper
.This works with
nano
too, with the option-B
so you can do it with a command line editor for 'sudo' tasks :-)