\

Show HN: F2 – Cross-Platform CLI Batch Renaming Tool

99 points - yesterday at 3:49 PM


Hey HN!

I'm excited to share f2, a command-line tool I built for fast and flexible bulk renaming of files. It's cross-platform (Linux, macOS, Windows), executes a dry-run by default, supports undo, and provides great flexibility in file renaming with several built-in variables and Exiftool integration.

I hope you find it useful!

Source
  • 037

    yesterday at 7:04 PM

    Very interesting, I’ll definitely give it a try!

    Another approach I recently discovered is an old but beautiful Unix-style tool for renaming files: vidir - edit a directory in your text editor. It’s part of the moreutils suite [1].

    You get the list of filenames in your editor – edit them as you like, save, exit, and it renames the files. It uses whatever editor is set in your $EDITOR env var, so it doesn’t have to be vi/vim.

    You can also pipe in a list of files, e.g. `find . -type f | vidir -`, to edit just the files you want - and you can even change paths (add, rename, remove directories) in the editor to move files around easily.

    To try it quickly on macOS: `brew install moreutils`

    [1] https://joeyh.name/code/moreutils/

      • ddlsmurf

        yesterday at 7:49 PM

        if you can forgive a shameless plug, I wrote https://github.com/ddlsmurf/fled some time ago and it serves me very well to this day. (It's not half as advanced as OP's tool but still useful)

    • bsnnkv

      yesterday at 4:59 PM

      Incredible name choice here - it's very rare that I get this feeling associating a new project with its name. I'm filled with feelings that touch on nostalgia, utility, UX design history and computing heritage when I hear the name F2 associated with a batch renaming tool. Great job!

        • nine_k

          yesterday at 11:25 PM

          It's indeed a name that immediately rings the right bell, without being an ungoogleable common noun or verb. Kudos.

          (Though for those of us who cut their teeth on tools like Norton Commander on the original IBM PC, the association would be with F6.)

          • ayoisaiah

            yesterday at 10:32 PM

            Thank you! I knew I had a winner the moment it popped into my head :)

        • j1elo

          today at 12:07 AM

          Small typo: the example given for "--replace-limit -1" reads:

              abc_abc.txt | 123_abc.txt
          
          but it should probably say:

              abc_abc.txt | abc_123.txt
          
          Funnily enough, the triplet example given in the tutorial for "--replace-limit" [1] (replacing either the first or the last of "abc_abc_abc") is written so that it has the effect of driving the reader to wonder "Ok but, what about the middle one????" :)

          A small idea for an alternative, more flexible option: "--replace-range", where you could use a well established syntax to represent ranges such as the one from Python and Go slices, so it's not only possible to replace from the leftmost or rightmost but also in-between.

          [1]: https://f2.freshman.tech/guide/tutorial#limiting-the-number-...

          • sandreas

            yesterday at 6:56 PM

            Awesome tool, thanks for sharing. One feature I would love to see on renaming tools is the following:

              -A - Sample of the of the ACTUAL file name
              -B - Sample of the desired filename
            
            e.g.

              f2 -A 001.pdf -B 001_renamed.pdf
            
            and this would automatically determine that every file with this "pattern" (001) should get the renamed prefix, so:

              001.pdf => 001_renamed.pdf
              002.pdf => 002_renamed.pdf
              ...
            
            Sounds weird, but there once was a tool written in dotnet that used machine learning techniques to achieve exactly this and it worked like a charm. Unfortunately I lost the reference and never found it again.

            Most important: Worked locally and did not send the filenames to chatGPT ;)

              • ayoisaiah

                yesterday at 10:31 PM

                You can already do this with F2 by using capture variables:

                  f2 -f '(\d+).pdf' -r '{$1}_renamed.pdf'
                
                Does that align with what you're looking for?

            • nine_k

              yesterday at 4:43 PM

              Dry-run by default! Use of metadata like EXIF! Undo!

              Here's some great product and UX chops, not just coding chops.

              • simonw

                yesterday at 4:29 PM

                I really like your CLI design here, clearly extremely well thought out, lots of great taste on display here: https://f2.freshman.tech/guide/tutorial

                The EXIF stuff to create folders based on the date photos were taken is fantastic! https://f2.freshman.tech/guide/organizing-image-library

                This tool solves a problem that I face all the time, I am definitely going to be using this often.

                  • ayoisaiah

                    yesterday at 10:41 PM

                    Thanks a lot Simon! I'm really thrilled to hear it's hitting the mark for you :)

                • sorenjan

                  yesterday at 6:25 PM

                  For photos, I'm guessing you can use Exiftool's built in geolocation feature to add the city and country first.

                  https://exiftool.org/geolocation.html

                  • devrandoom

                    yesterday at 6:46 PM

                    Wow, this goes instantly to my toolbox. Thanks for writing this and sharing it!

                    It only happens a few times a year that I need to batch rename. Buy when I do my adrenaline levels go up by about two espressos.

                    • otterpro

                      yesterday at 4:32 PM

                      Wow, it can integrate with exiftool. I use exiftool to rename photo files, but I think f2 offers more flexible renaming features.

                      • yesterday at 3:53 PM

                        • hoppp

                          yesterday at 8:14 PM

                          The undo functionality is a nice touch. I know cuz I write scripts to rename files and made mistakes before.

                          • batrat

                            yesterday at 7:18 PM

                            In windows I use PowerToys - power rename to rename files. But I'm not a power user I rarely need renaming something.

                            • porridgeraisin

                              yesterday at 7:07 PM

                              Really nice, wow.

                              Honestly I don't see myself remembering and using the variables features(which gives the exiftool feature others here are raving about) but it's already insanely good without that. Love the ability to refine your selection with further -f flags. Also the ability to rename while create nested paths is so good.

                              Suggestion, having an "up"[1] mode where you can see the dry run output in a live updating thing when you are adding further -fs and -rs.

                              [1] https://github.com/akavel/up