Google Answers Logo
View Question
 
Q: Using CP and XARGS on Windows to copy files within modified date range ( No Answer,   2 Comments )
Question  
Subject: Using CP and XARGS on Windows to copy files within modified date range
Category: Computers > Programming
Asked by: buddahlee-ga
List Price: $40.00
Posted: 03 Jan 2006 12:20 PST
Expires: 05 Jan 2006 18:46 PST
Question ID: 428559
The first line is the command. The second and 3rd lines are the errors
I am getting.
1. C:\backups>find \\server1\f\directory1\*.* -mtime -2 -print0 |
xargs cp {} d:\archive\archive_directory

2.xargs: argument line too long
3.cp: when copying multiple files, last argument must be a directory

All I am trying to do is copy the files resulting from the CP command
to d:\archive\archive_directory. I've tried various versions of this
to include various switches for CP and XARGS with no good results.
I've use the {} option as well as specifying the source directory. The
copy command seems to work; it does print out a list of the files with
the correct modification dates, but I cannot get them to copy to the
destination directory. This is being done on a Windows 2003 server
with the Unix utilities (find, cp, xargs) installed. Need solution
quickly.

Clarification of Question by buddahlee-ga on 05 Jan 2006 18:43 PST
The alternate suggestion:
"C:\backups>for /F %i IN ('find \\server1\f\directory1\*.* -mtime -2')
DO cp %i d:\archive\archive_directory"
is good. This helps a lot. But although it works from a command line,
it does not work from a batch file (Need to schedule it as backup
job.) Thanks.

The following suggestion on Windows:
"find . -mtime -2 -print0 | xargs -n1 cp  --target-directory=/tmp/test"
generated the following error: cp: d:/proj/out: omitting directory
Answer  
There is no answer at this time.

Comments  
Subject: Re: Using CP and XARGS on Windows to copy files within modified date range
From: m0hi1-ga on 05 Jan 2006 02:05 PST
 
If you are trying to copy files from \\server1\f\directory1\ which are
less than 2 days old to d:\archive\archive_directory then try one of
this command.

For 'for' of windows
C:\backups>for /F %i IN ('find \\server1\f\directory1\*.* -mtime -2')
DO cp %i d:\archive\archive_directory

For 'for' of unix shell
C:\backups>for i in `find \\server1\f\directory1\*.* -mtime -2`; do cp
$i d:\archive\archive_directory; done
Subject: Re: Using CP and XARGS on Windows to copy files within modified date range
From: dazchambers-ga on 05 Jan 2006 04:22 PST
 
Try specifying a target directory to cp:

find \\server1\f\directory1\*.* -mtime -2 -print0 | xargs -n1 cp 
--target-directory=d:\archive\archive_directory

The following worked under Linux:
find . -mtime -2 -print0 | xargs -n1 cp  --target-directory=/tmp/test

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy