I think you've misunderstood how the -execdir
parameter of find
works. The rename
command will be run from the subdirectory containing the matched file, but it will still be called for every matched file. Your rename
arguments include the *
wildcard, so in each subdirectory that has N files, you'll call rename
on N^2 files. (+1 for the "{}"
filled in by find
.)
The problem is, I think your rename
regex only works because of the *
. I don't think it will actually match the "{}"
part.
So summarize (including comments from above):
- Use
-regex
to find only the files you want to rename.
- Use
+
instead of ;
to group files.
- Drop the wildcard
*
.
- Fix the
rename
regex to operate on the basename of the matched files (find
will pass on the paths with ./
prefix).
An alternative might be to find all subdirectories that have a file/folder beginning with space, and then running rename *
in just those directories. Gut feeling says the first approach is more efficient, but it probably depends on the number and distribution of the matched files.
(Sorry, I did not have the time to actually write the one-liner for you!)