DEV Community


quick backup of a file

Kelly Stannard
Developer. Design pattern enthusiast. Tilting at Agile practices.
・1 min read

Recently I started trying to get competent at bash's string expansion phase and realized I could do the following to backup a file:

$ mv path/to/file.txt{,_}

Then to restore the file, swap the , and _ in the brackets.

$ mv path/to/file.txt{_,}

String expansion is a step that runs before executing the shell command so what is really being run can be viewed with the following:

$ echo mv path/to/file.txt{_,}
mv path/to/file.txt path/to/file.txt_

Discussion (0)