0

I had a command line instruction to move a 100k’s of jpgs to the correct directory on the same disk/volume/partition and without using xargs. The quirk is that the jpgs have spaces and multiple periods or dots. For example: “wacky image.45 xyz.001 00.78.jpg”. The other quirk is that wacky pattern refers to a set, so there a several thousand of those jpgs with an additional set of numbers inserted before the final jpg extension: “wacky image.45 xyz.001 00.78.details_0_34748-836389.jpg. I’m not sure who made the design decision for this machine but it wasn’t me! Anyway I had something along the lines of:

for f in ./“wacky image.45 xyz.name.s.00.78”*; do
    mv $f /path/to/destination/;
done

I’m not sure what I’m missing.

Edit: Using MacOS terminal app, which behaves like BSD for the most part.

  • 2
    Put $f in double quotes: "$f" – Arkadiusz Drabczyk May 22 '19 at 21:07
  • The first and only sensible thing to do with a working "command line instruction" is renaming all those files. – Bananguin May 22 '19 at 21:53
  • Arkadiusz Drabczyk, that's what I was looking for. The for f in blah blah blah allows mv to avoid the arguments list too long situation. – SciGuy May 23 '19 at 4:26
0
for f in ./"wacky image.45 xyz.name.s.00.78"*; do
    mv "$f" /path/to/destination/;
done 

(Note the quotes) has the same problem as

mv ./"wacky image.45 xyz.name.s.00.78"* /path/to/destination/

they both glob. What you need for "millions" of files is

find . -iname 'wacky image.45 xyz.name.s.00.78*'  -exec mv "{}"  /path/to/destination/

Or if you want some per file logic

while read -r F ; do
    mv "$F"  /path/to/destination/
done < <(find . -iname 'wacky image.45 xyz.name.s.00.78*' )
  • Well, it's pretty rare to actually move >1M files at once. It's usually several sets of images that range in number from 50k to 800k, but I take your point! – SciGuy May 22 '19 at 22:29
0

Arkadiusz Drabczyk got it right with "Put $f in double quotes: "$f"" up above.

Using this, I'm able to mv 1M+ files to different directory on the same disk/volume/partition. I edited the question, but I'll put it here too. I'm using MacOS 10.14 and the terminal app, which behaves like BSD for the most part. FOr better or worse, Apple no longer allows 32-bit applications on it's OS, so every CLI tool was compiled in 64-bit. Maybe this is what allows large argument lists?

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.