Ubuntu – Copy files from one folder to another folder within specific date range

bashcommand linecopy

I am already using below command to copy files from a specific date.

Previously I used this command and it worked well but now it was showing an error:

-bash: /bin/cp: Argument list too long

Commends used:

cd /share/new/
cp `find . -type f -newermt '16 july 2018'` /share/test

I need to copy all files in the folder "new" from July 20th to today date. How can I achieve this?

Best Answer

Don't use cp directly with the output of find.

It might passes way many too files in a single step (and that's why you get the error Argument list too long).

Use the -exec parameter of find, which execute the given command passing a every matched file to cp, one at a time:

cd /share/new/
find . -type f -newermt '16 july 2018' -exec cp {} /share/test \;