[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The returned value of -prune and its documentation

From: Cristian Zoicas
Subject: The returned value of -prune and its documentation
Date: Tue, 30 Apr 2019 13:09:42 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.2

Hello all

The manual page of find says the following for the -prune action:

      True; if the file is a directory, do not descend into it. If -depth is
      given, false; no effect.  Because  -delete implies -depth, you cannot
      usefully use -prune and -delete together.

So I understand that if -depth is given then -prune behaves as follows:

    a) returns false
    b) it has no effect.

The point b) is clear but I think that the documentation is not correct for
the returned value (point a)). See the example below.

----- BEGIN EXAMPLE -----

The following directory structure and the following statement show that -prune
does not return false when -depth is given.

mkdir -p test/s_files/
echo a-top > test/a-top.txt
echo s-top > test/s-top.txt
echo a > test/s_files/a.txt
echo s1 > test/s_files/s1.txt
echo s2 > test/s_files/s2.txt

find ./test/ -depth \( -name s\* -a -prune -a -printf "printed with printf: 
%p\n" \) -o -exec bash -c 'echo printed with echo: {}' ';

The result of this statement is:

printed with printf: ./test/s_files/s1.txt
printed with printf: ./test/s_files/s2.txt
printed with echo: ./test/s_files/a.txt
printed with printf: ./test/s_files
printed with echo: ./test/a-top.txt
printed with printf: ./test/s-top.txt
printed with echo: ./test/

By reasoning step by step we have:

1) file ./test/s_files/s1.txt is found
2) find stars evaluating the expression;
3) -name s\* and returns true
4) if -prune returned false because of the presence of -depth then the result 
of the
   parenthesis \( -name s\* -a -prune -a -printf "printed with printf: %p\n" \) 
   be known (false) and -printf would not be executed. Instead -exec would have 
   be evaluated.

----- END EXAMPLE -----

I would add one more more thing: the documentation of -prune would be
reformulated and  explicitly specify that -prune returns true for "both files
and folders".

Best regards

reply via email to

[Prev in Thread] Current Thread [Next in Thread]