How to transform -exec to xargs for better performance in UNIX SHELL?

56 Views Asked by At

Sorry, a very simple question. How can I transform the following working code to copy all JSON files to the parent folder, using xargs? The motivation is to work on a lot of files (150K files).

find . -regex '.*\.json' -exec cp {} ../ \;

I tried the following:

find . -regex '.*\.json' | xargs cp ../

Is this a correct command? Anyway, I got an error:

cp: .//abc.json is not a directory

This error is not the primary question here, but I just wanted to get know-how of this kind of operation. I heard that xargs is faster and efficient. Thanks!

0

There are 0 best solutions below