0

Can mmv, a mass move utility, nicely rename files from:

  • foo.txt
  • bar.txt
  • baz.txt

to:

  • 1.txt
  • 2.txt
  • 3.txt

The man page is intriguing, but I don't quite follow the directions:

   Rename all *.jpeg files in the current directory to *.jpg:

  mmv '*.jpeg' '#1.jpg'

Can the #1 variable be set to an integer which increments? While I don't doubt that this is possible, is it equally easy (or hard) to just use a bash or other script?

Ignoring the possible problem of overwriting 1.txt for simplicity. Or, copy into a subdirectory instead.

see also:

https://stackoverflow.com/questions/3211595/

https://stackoverflow.com/questions/880467/

Rename files by incrementing a number within the filename

0

I don't have that program on my system — in fact, I don't specifically recall hearing of it before — but I read this copy of the man page, and it appears that the program does not include the functionality that you want.  However, if you especially want to do this with mmv, you might want to try this:

mmv -an "*.txt" bogus.target > /tmp/mmv.list

The -n tells mmv not to do any moves, but just to report what it would have done if you hadn't specified -n.  The -a tells it to append all the text files into the one file bogus.target — in fact, the man page gives a very similar example (but without the -n option) — I use it here simply to persuade mmv to allow multiple source files to collide into a single target.  This should produce a /tmp/mmv.list file that looks something like

bar.txt -> bogus.target
baz.txt -> bogus.target
foo.txt -> bogus.target

(I assume that it will list the files either in lexicographical (alphabetical) order, or directory order (which may appear to be an arbitrary order).  If you want some other order, you will need to find some way to specify that.)  Then process the file (e.g., with a script, TBD) to replace the occurrences of bogus.target with 1.txt, 2.txt, 3.txt, etc.  Then execute

mmv < /tmp/mmv.list

Caveats: I haven't tried this (since, as I said, I don't even have the software).  You should probably do a dry run first on some unimportant files, and/or backup all your files before doing this.

Note also that this is probably at least as much work as some of the answers to the questions you linked to.  As I said, I offer this suggestion just in case you especially want to do this with mmv.

P.S. My answer (above) was partially inspired by this one.

  • thanks for the research. I'll take a closer look probably tomorrow. – Thufir Feb 16 '16 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.