DEV Community

Kelly Stannard
Kelly Stannard

Posted on

quick backup of a file

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_
Enter fullscreen mode Exit fullscreen mode

Top comments (0)