F2: Fast And Safe Batch Rename Tool For The Command Line (Cross-Platform)

F2 is a command-line file and folder batch renaming tool written in Go. The tool is fast, safe (runs several validations before renaming, and allows undoing the batch rename), and runs on Linux, macOS and Microsoft Windows.

F2 batch file rename

The mass rename command line tool is fairly new, having its first stable release back in February 2021, but it’s already quite mature, with features like string replacement, insertion of text as a prefix, suffix or other position in the file name, change the letter case, rename using auto-incremental numbers, and so on. Find and replace using regular expressions is also supported.

The tool can show a preview of the new file and folder names (simply omit the -x command line flag, which is used to apply the changes), and it also supports undoing the last batch renaming operation in case you change your mind and want to revert the changes. 

To ensure that the rename operations are safe, F2 also runs several validations before carrying out a rename operation. In case the tool finds conflicts, like the target destination already existing, invalid characters in the target path, an empty filename, etc., it can automatically resolve them using the --fix-conficts / -F flag.

To make batch renaming easier, F2 includes several built-in variables, like {{ext}} for the file extension (including the dot), {{f}} for the original filename excluding the extension, and {{p}} for the parent directory name, and more. Exif and ID3 tags are also available as built-in variables, so you can batch rename pictures using their Exif data, and music files (such as MP3, FLAC, OGG, M4A, ACC, etc.) based on their ID3 tags.

F2 is fast too. You can find some benchmarks on its project page.

Even though it has many features, F2 doesn’t have a simple-to-use user interface where all you have to do is check some boxes and start the batch rename. Instead, you must enter some command line options, and optionally use regular expressions to rename your files the way you want. For example, to replace img with Image in the name of all the files in the current directory using F2, you’d use:

$ f2 -f 'img' -r 'Image'
+-------------+---------------+--------+
|    INPUT    |    OUTPUT     | STATUS |
+-------------+---------------+--------+
| img-001.png | Image-001.png | ok     |
| img-002.png | Image-002.png | ok     |
| img-003.png | Image-003.png | ok     |
+-------------+---------------+--------+

The command used in the example above only shows a preview of the original files and their new filenames, but doesn’t perform the renaming operation. When you want to apply the changes, append -x to the command. So in this example, the above command becomes f2 -f 'img' -r 'Image' -x.

You might also like: A Quick Introduction To fzf (Interactive Command-Line Fuzzy Finder)

Here’s another example in which I’m batch renaming some music files (mp3) from 001.mp3, etc., to descriptive names using their audio ID3 tags:

$ f2 -f ".*.mp3" -r "{{id3.artist}} - {{id3.album}} - {{id3.track}} - {{id3.title}}.mp3" -x
+---------+----------------------------------------------------+--------+ | INPUT | OUTPUT | STATUS | +---------+----------------------------------------------------+--------+ | 001.mp3 | Tool - Fear Inoculum - 1 - Fear Inoculum.mp3 | ok | | 002.mp3 | Tool - Fear Inoculum - 2 - Pneuma.mp3 | ok | | 003.mp3 | Tool - Fear Inoculum - 3 - Invincible.mp3 | ok | | 004.mp3 | Tool - Fear Inoculum - 4 - Descending.mp3 | ok | | 005.mp3 | Tool - Fear Inoculum - 5 - Culling Voices.mp3 | ok | | 006.mp3 | Tool - Fear Inoculum - 6 - Chocolate Chip Trip.mp3 | ok | | 007.mp3 | Tool - Fear Inoculum - 7 - 7empest.mp3 | ok | +---------+----------------------------------------------------+--------+

Notice that here I’ve used the -x flag, which applies the mass file renaming. I won’t go into any more examples here, since the F2 wiki is well documented, and it includes various batch rename examples.

You might also like: GUI To Batch Rename Files On Linux With Exif And Music Tags Support: Inviska Rename

Download F2 command line batch rename tool

F2 is available to install from source, or you can download a precompiled binary for Linux (including Termux/Android), Windows or macOS.

In case you use xplr, you can find an F2 xplr integration hack here.

Posted by WordPress Guru