[X-Unix] Script - works, but not where I need it to

Bert Knabe bert.knabe at lubbockonline.com
Wed Jun 30 22:39:35 PDT 2004


On Jul 1, 2004, at 12:23 AM, William H. Magill wrote:

>
> On 30 Jun, 2004, at 21:08, Bert Knabe wrote:
>
>> I have a shell script to copy all files added to a folder in the last 
>> 24 hours to another folder. It works, but only when invoked from my 
>> computer. When invoked on our Xserve, it gets the following error:
>>
>> [computer:/Users/Shared] admin% sh filecopy22.txt
>> filecopy22.txt: /usr/bin/find: Argument list too long
>>
>> The script is just a line or two:
>>
>> find /Volumes/composing/\ \ \ Running\ Ads/* -mtime 1 -exec cp -p {} 
>> /Volumes/Online/\PDF\'S/In/ \;
>
> Pretty standard problem with find (and ls) -- the argument list is the 
> number of files in the directory(s) "found". On the server it's 
> probably much larger than on your local machine.
>
> You need to use xargs ... which normally you pipe into. (man xargs).

Mike Gorsky emailed me off list and gave me a solution - but I'll look 
up xargs. For anyone who's curious, here's the working script:

     find /Volumes/composing/\ \ \ Running\ Ads/ -type f -mtime 1 -exec 
cp -p {} /Volumes/Online/\PDF\'S/In/ \;

> Haven't used it in ages, so off hand I forget the syntax when using it 
> with find ... I think it is to simply break the find before the -exec 
> command and pipe it into xargs ...
>
> find ... -mtime 1 \; | xargs cp -p  /Volumes/Online/\PDF\'S/In/
>
> By the way -- if you plan on doing lots of stuff like this from the 
> command line, loose the apostrophe and make it simply "PDFs" or 
> "PDF-s"   ... ditto for spaces in file names -- use a dash or 
> underscore. It makes command line life much easier.

The only reason I didn't change them was the amount of other stuff that 
would have to be changed to accommodate that change. But if I wind up 
doing more of this, I'll make sure I have more input into file and 
folder names. :)

BTW, is there a particularly good book on shell scripting, or am I as 
well of searching the web?

Thanks,

Bert Knabe
Computer Technician
Lubbock Avalanche Journal
bert.knabe at lubbockonline.com
(806) 766-2158

Nothing contained in this email is intended to be an offer to commit 
Morris Communications Company to any purchase, sale, contract, or other 
course of action.



More information about the X-Unix mailing list