1. 10
  1.  

  2. 11

    This missed my favorite technique, which is to ls > copy_files.sh and then edit the script in vim. It’s not very impressive, but - at least for me - much faster than writing the code presented in this article. :)

    1. 11

      I do that with vidir, it opens vim with a number and the filename per line, you can change the filename and when you exit vim it will just rename changed filenames by looking up the old name using the number.

      1. 1

        See also my favourite tool, qmv from renameutils. Sounds like the same as your vidir but will just open whatever your $EDITOR is and doesn’t add line numbers.

        1. 1

          Wow, that’s almost what I wrote in python, dump file lists into lines, and rename or delete from the diff of the output. Sometimes I need create hardlink or move files around, and vidir seems only does rename?

          1. 2

            Deleting and moving files works too, hardlinks not.

            $ tree
            .
            ├── a
            ├── b
            └── c
            
            0 directories, 3 files
            $ vidir
            1   ./foo/bar/a
            3   ./foo/c
            :wq
            $ tree
            .
            └── foo
                ├── bar
                │   └── a
                └── c
            
            2 directories, 2 files
            
        2. 3

          same here

            ls *.txt | vim -
          
            abc.tx -> mv abc.tx abc.txt
          
            :w !sh
            q!
          
          1. 1

            Incidentally, I wrote a little Vim plugin earlier this week to streamline that workflow a bit, which makes editing that kind of stuff in Vim a bit easier.

            1. 1

              Nice method! I use ranger for bulk-renaming files in a vim-style workflow. However I frequently find myself installimg ranger for that single purpose. Your method seems more easily accessibie.

            2. 9

              Doesn’t work well for nested subdirectories cases, but C-x C-q in dired in Emacs is a really convenient method.

              1. 3

                This is my favorite way of bulk-editing filenames, it’s so nice to be able to do anything Emacs can do on a text file on a directory of filenames.

                1. 2

                  I think there is a large amount of emacs users that don’t know this trick. When I first found out about it a couple of years ago (just use the regular “toggle read-only” command sequence!) my jaw dropped. I have never had to deal with hacks like the ones outlined in the article since. :)

                2. 3

                  zsh’s “zmv” combined with noglob (alias mmv="noglob zmv -W") allows you to do basic renames with glob syntax: mmv *.txt *.csv. More generally zmv can be used to perform copies as well. See the documentation for some more examples.

                  This doesn’t beat vidir or rename, or more complex scripts, but it definitely has a very practical syntax which works for 90% of the time I need some quick mass renames. I still use rename, vidir or custom scripts.

                  1. 1

                    I haven’t used it much yet but F2 is the tool I intend to turn to first next time I have a bulk rename task. Usually I just write a shell loop or a little Python.

                    1. 1

                      I have a script called each, which lets me do this:

                      ls *.JPG | each mv $+x $+{x%.JPG}.jpg
                      

                      If the problem is simple enough to be solved using variable substitutions, then that’s usually what I do.