DEV Community

Kelly Stannard
Kelly Stannard

Posted on

4 2

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)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More