bash - understanding escaped parentheses in find -
i've cobbled below, , seems work, possible exception of "! -empty". 1 thing i'm learning (as go) because works, doesn't mean it's right or formed correctly...the question have how determine requires parentheses , doesn't in find command?
in os x, -and "implied juxtaposition of 2 expressions not have specified"
my goal have find: find directories on 5 minutes old, not empty, , not .dot (hidden -i.e. "." , "..")
count="$( find . -type d -mmin +5 \! -empty \( ! -iname ".*" \) | wc -l )" echo $count if [ "$count" -gt 0 ] ; echo $(date +"%r") "$cust_name loc 9: "${count}" directories exist process, moving them" >> $logfile find . -type d -mmin +5 \! -empty \( ! -iname ".*" \) | xargs -i % mv % ../02_processing/ cd $processingpath # append time , directories processed in files_sent.txt date +"---- %a-%b-%d %h:%m ----" >> $filessentlog ls >> $filessentlog find . -type f -print0 | xargs -0 /usr/local/dcm4che-2.0.28/bin/dcmsnd $aet@$peer:$port echo $(date +"%r") "$cust_name loc 10: processing ${count} items..." >> $logfile # clean processed studies > processing processed echo $(date +"%r") "$cust_name loc 11: moving ${count} items 03_processed" >> $logfile mv * $processedpath else echo $(date +"%r") "$cust_name loc 12: there no directories process" >> $logfile fi could do:
find . -type d -mmin +5 \! -empty \! -iname ".*" ? or not right reason?
find has next operators listed in order of precedence (highest -> lowest)
() !|-not -a|-and -o|-or , (gnu only) note: tests , actions have implied -a linking each other
so if not using operators, don't have worry precedence. if using not in case, don't have worry precedence either, since ! exp exp2 treated (! exp) , (exp2) expected, due ! having higher precedence implied and.
example precedence matters
> mkdir empty && cd empty && touch && mkdir b > find -mindepth 1 -type f -name 'a' -or -name 'b' ./a ./b the above got treated find -mindepth 1 (-type f , -name 'a') or (-name 'b')
> find -mindepth 1 -type f \( -name 'a' -or -name 'b' \) ./a the above got treated find -mindepth 1 (-type f) , ( -name 'a' or -name 'b')
note: options ( i.e. -mindepth, -noleaf, etc... ) true
conclusion
the next 2 uses of find same
find . -type d -mmin +5 \! -empty \( ! -iname ".*" \) | wc -l find . -type d -mmin +5 \! -empty \! -iname ".*" | wc -l both treated as
find . (-type d) , (-mmin +5) , (! -empty) , (! -iname ".*") | wc -l bash shell find quoting
No comments:
Post a Comment