2014-10-03 2 views
0

필자는 man 페이지를 다루었으며 find가 테스트 순서를 어떻게 수행하는지 알지 못합니다.find의 평가 순서

Solaris 찾기 명령에는 "테스트"와 "작업"이 분리되어 있지는 않지만 표현식의 일부로 테스트됩니다.

find . -type d -mount -ctime +5 -prune -exec 'rm {}' \; 

같은 명령 라인이 경우

, 그것은 "타입 D"및 "-ctime +5"가 먼저 평가되는 것을 보장 "간부 'RM {} \;" 따라서 올바른 파일 만 삭제됩니까?

+0

에서 거의 동일 견적을 He're,하지만 난'RM은 {}'인용해야한다고 생각하지 않습니다. 쉘이 어떤 식 으로든 먼저 해석 할 경우'{}'를 인용 할 수 있고, 대부분의 쉘에서 인용 부호를 사용하지 않을 수도 있습니다. – BroSlow

답변

0

설명 find

다양한 구현은 man 페이지에 operands 다른 이름을 호출하는 경향이있다. 그러나 posix 표준을 따르는 모든 find 구현의 일반적인 실행은 동일합니다.

find [-H | -L] path ... [operand_expression ...] 

매뉴얼 페이지 따옴표 posix find man page

에서 가져온 경우 각각의 설정이 감동 expressions, 즉 명시 적 연산자 expressions 분리가없는 (-operand (Argument)을 의미), 분리 암시 -a (AND) 연산자를 가지고 그들.

expression [-a] expression 
Conjunction of primaries; the AND operator is implied by the juxtaposition of 
two primaries or made explicit by the optional -a operator. 
The second expression shall not be evaluated if the first expression is false. 

결론

그래서 expressions 왼쪽에서 오른쪽으로 실행해야합니다 posix 표준을 따르는 모든 구현; 및

find . -type d -mount -ctime +5 -prune -exec 'rm {}' \; 

모든 이전 operands에 해당하는 경우 -exec 만 실행된다는 것을 의미

find . -type d -a -mount -a -ctime +5 -a -prune -a -exec 'rm {}' \; 

에 해당합니다.

다른 또한 -exec이 발견 구현에 의해 명시 적으로 action를 호출 할 수 없습니다 수 있지만, 그것은 여전히 ​​(즉 -print 조치를 교체)

If no expression is present, -print shall be used as the expression. 
Otherwise, if the given expression does not contain any of the primaries -exec, 
-ok, or -print, the given expression shall be effectively replaced by: 

(given_expression) -print 
유사한 방식으로 치료를받을 것을 주목할 필요가

편집

기술적으로 사실이없는 모든 IMPL 진술은 posix 불만이어야합니다. 대답에 관련없는 solaris find man page

expression [-a] expression 
Concatenation of primaries (the and operation is implied by the juxtaposition of two primaries). 
+1

요청한대로 "보장"되지는 않지만 충분히 가깝습니다. 많은 감사합니다. – Envite

+0

@ Envite 모든 구현이'posix'에 부합하지 않아야한다는 것은 사실입니다. 'solaris find' 맨 페이지에서 인용문을 추가했습니다. – BroSlow

+1

예, 정확히 봤습니다. "첫 번째 표현식이 거짓이면 두 번째 표현식은 평가되지 않습니다."라는 설명이 없습니다. 나는 그 질문에 나를 이끌었다. – Envite