I have extracted clips from a video with ffmpeg, following this pattern 'clip-%4d.png'.
This has yielded files like: clip-0001.png
, clip-0002.png
and so on.
I have then applied many filters with imagemagick "convert" to those pictures, and it ran for a couple hours.
I realised my list order is broken after clip-9999.png
, it becomes clip-10000.png
and up to clip-40000.png
, successfully ruining my sequence of clips.
I would like to convert all my clips to follow the sequence clip-00000.png
, clip-00001.png
up to clip-40000.png
.
I could restart the whole process using pattern 'clip-%5d', but I am told rename
utility might solve my problem; however I am myself quite unfamiliar with regular expressions.
Using a Perl-based
rename
commandIf you've got a Perl-based
rename
command, that's pretty easy:I note in passing that if you've really got about 10,000 clips to rename, you may need to work with
xargs
orfind
to avoid problems with 'argument list too long'.or:
Since your names don't contain spaces, either will work. If there are spaces to worry about, use the
find
-only variant, assuming yourfind
supports the POSIX 2008+
notation tofind
. This can be applied to any of the other answers with a little care.I note that this Perl script avoids having to execute
mv
10,000 times, so it is likely to outpace any of the shell scripts that executesmv
for each file rename. For a one-off exercise, this may not matter, but it will become more of an issue when you get to more than 100,000 clips.Also, the script below has the option to read the file names, one per line, but it slurps the whole lot into memory, which isn't dreadfully efficient (but was present in the original version of the script and has been kept, even though I've hardly ever used the option). Assuming a sane modern machine (say 1 GiB of memory, but less would be sufficient), that is not going to be a problem with just 10,000 names of length 12 characters each. So you could also use:
A Perl-based
rename
scriptIf you've not got a Perl-based
rename
command, this is the one I use. It was originally from the 1st Edition of the Camel Book, but has been modified a little over the years: