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

Philip Ershler ershler at cvrti.utah.edu
Wed Jun 30 22:47:45 PDT 2004


On Jun 30, 2004, at 11:39 PM, Bert Knabe wrote:

>
> 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?
>
>
	Depends on what shell you are using but the O'Reilly Series is 
excellent. If you are using the bash shell (now the default on OS X, I 
believe) Have a look at

Learning the bash Shell by Cameron Newham & Bill Rosenblatt. It's part 
of the Unix Shell programming series.

Phil



More information about the X-Unix mailing list