forked from ayoisaiah/f2
-
Notifications
You must be signed in to change notification settings - Fork 0
Undoing renaming mistakes
Ayooluwa Isaiah edited this page Feb 2, 2023
·
2 revisions
F2 makes it really easy to revert a renaming operation if mistakes were made. A
backup file is automatically created for each renaming operation that is
performed and stored in the ~/.local/share/f2/backups
directory on Linux,
~/Library/Application Support/f2/backups
on macOS, and
%LOCALAPPDATA%\f2\backups
on Windows. For example, given the following
operation:
pwd
/home/ayo/Pictures/Wallpapers
f2 -f '.*' -r "unsplash-image-%03d" -e
┌─────────────────────────────────────────────────────────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| *********************************************************************************** |
| kevin-wong-tt7aK2yV7xo-unsplash.jpg | unsplash-image-001.jpg | ok |
| nathan-anderson-7TGVEgcTKlY-unsplash.jpg | unsplash-image-002.jpg | ok |
| photo-1434907652076-85f8401482c3.jpg | unsplash-image-003.jpg | ok |
| photo-1510272839903-5112a2e44bc6.jpg | unsplash-image-004.jpg | ok |
| photo-1521579971123-1192931a1452.jpg | unsplash-image-005.jpg | ok |
| samuele-errico-piccarini-t4OxCpKie70-unsplash.jpg | unsplash-image-006.jpg | ok |
| valentin-salja-VMroCCpP648-unsplash.jpg | unsplash-image-007.jpg | ok |
└─────────────────────────────────────────────────────────────────────────────────────┘
Executing the operation will produce a JSON backup file in the user's home directory as shown below:
f2 -f '.*' -r "unsplash-image-%03d" -e -x
ls ~/.local/share/f2/backups
_home_ayo_Pictures_Wallpapers.json
This backup file is used to revert the operation when you specify the --undo
or -u
flag. The command to revert an operation must be executed in the
directory where the original operation was performed, otherwise the backup file
will not be found.
f2 -u # dry-run
┌─────────────────────────────────────────────────────────────────────────────────────┐
| ORIGINAL | RENAMED | STATUS |
| *********************************************************************************** |
| unsplash-image-007.jpg | valentin-salja-VMroCCpP648-unsplash.jpg | ok |
| unsplash-image-006.jpg | samuele-errico-piccarini-t4OxCpKie70-unsplash.jpg | ok |
| unsplash-image-005.jpg | photo-1521579971123-1192931a1452.jpg | ok |
| unsplash-image-004.jpg | photo-1510272839903-5112a2e44bc6.jpg | ok |
| unsplash-image-003.jpg | photo-1434907652076-85f8401482c3.jpg | ok |
| unsplash-image-002.jpg | nathan-anderson-7TGVEgcTKlY-unsplash.jpg | ok |
| unsplash-image-001.jpg | kevin-wong-tt7aK2yV7xo-unsplash.jpg | ok |
└─────────────────────────────────────────────────────────────────────────────────────┘
f2 -ux # revert the renaming operation
Note that:
- The auto created backup file is specific to the working directory where F2 is executed. It is overwritten each time you rename files in that working directory.
- The backup file is automatically deleted after a successful reversion.
- A backup file is not created when an operation is reverted, but you can easily repeat the original renaming command.
- A backup file is auto created even if there are errors while the renaming operation is being performed. See recovering from failures.
- If any of the renamed files are changed by another program between the time the renaming operation is performed and the time a reversion is attempted, it may cause the reversion to fail for that particular file. You will be notified of which files are unable to be reverted and why.
- Any directories that were created in the original renaming operation will be left alone and not deleted when reverting the operation.