[Tutor] symlinking dirs with spaces

mike mike at froward.org
Mon Apr 29 04:04:44 CEST 2013


On 04/28/2013 08:59 PM, Dave Angel wrote:
> On 04/28/2013 08:54 PM, mike wrote:
>> On 04/28/2013 07:37 PM, Dave Angel wrote:
>>> On 04/28/2013 08:17 PM, mike wrote:
>>>>
>>>>>     <SNIP>
>>>>>>
>>>>
>>>> def sync_new():
>>>>      durFind = raw_input("Enter the duration of time in days you
>>>> want to
>>>> link")
>>>>      durFind = int(durFind)
>>>>      fileExcl = "*torrent*"
>>>>      linkNew = ['find', '%s' % musicDir, '-maxdepth 2', '-mtime %s' %
>>>> durFind, '-not', '-name', '%s' % fileExcl, '-exec addsync {} \;']
>>>>      subprocess.call(linkNew)
>>>>
>>>         <SNIP>
>>>>
>>>> Running the script with the pushnew argument results in the following
>>>> error from find:
>>>>
>>>> find: unknown predicate `-maxdepth 2'
>>>>
>>>> I'm thinking this is also related to my usage of subprocess? I just
>>>> started carving this out right now so I'm still debugging but if anyone
>>>> sees anything obvious I would appreciate it.
>>>>
>>>
>>> Your linkNew list doesn't have separate items for each argument to find.
>>>   The first example is that "-maxdepth" and "2" should be separate list
>>> items.  The only other spot I notice is the -exec item, which should be
>>> distinct from the following.
>>>
>>> I don't understand why you have things like '%s' % musicDir, when
>>> musicDir is already a string.  That list item should be just musicDir,
>>> which would read much better.
>>>
>>>
>> I separated the maxdepth argument with '-maxdepth', '2', seems and now
>> it is focusing on the exec portion which i'm trying to figure out how to
>> separate and make it sane as far as single/double quotes go.
>
> If I were sure enough about the syntax to find (I only use -exec about
> once a year, and have to look it up each time), I could be explicit.
>
> But if you want   -exec addsync {}
> you should be using 3 different list items.
>
> I don't think the \; means anything useful since you're not using the
> shell.  But if find needs a semicolon there somehow, I might try just ";"
>
> Could you show us exactly what the find command would look like if you
> were executing it at the bash shell prompt?
>
>
>>
>> Can you elaborate on what you mean regarding the musicDir variable? I
>> have a loadDir which specifies where the symlinks reside but the actual
>> root of the media directory is /opt/data/music and it's organized via
>> directories based on genres which is why I am specifying musicDir
>> instead of loadDir for this function
>>
>
> Simple.  Since musicDir is a string,
>      "%s" % musicDir
> is a verbose way of saying
>       musicDir
>
> Likewise for fileexecl.  Neither is an error, just confusing.
>
>

I didn't see your response dave, this would be the full syntax:



find /opt/data/music -maxdepth 2 -mtime -5 -not -name "*torrent*" -exec 
addsync {} \;




More information about the Tutor mailing list