quick backup of a file

github logo ・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_
twitter logo DISCUSS
Classic DEV Post from Jun 14 '19

Stopping Bad Habits Before They Stop You

Stop habits before they derail your life.

Kelly Stannard profile image
Developer. Design pattern enthusiast. Tilting at Agile practices.

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️