Bash find : another problem with prune

Hello.

I am searching file between dates and try to apply the comments from Chubler_XL in my thread : Linux find command : how to use multiple conditions

But i get a null result as i am expecting to find 32 files.

Setting my computer date to the date of the thread ( 30/05/2019 ) and running the Chubber_XL examples I got the correct result.

Running the test to day (2020-02-03) on yesterday data between 2020_02_02_18h_50m_00s and 2020_02_02_23h_59m_59s, here is my try :

SEARCH_PATH="/home/user_bidon"
FILE_DATE_REF_DEB="/run/media/user_bidon/SANDSK128G-4/ASUS_GGV/TEMP/001_CONFIG_FILE_DURING_CONFIGURATION/foo_ref_date_2020_02_02_18h_50m_00s.txt"
FILE_DATE_REF_END="/run/media/user_bidon/SANDSK128G-4/ASUS_GGV/TEMP/001_CONFIG_FILE_DURING_CONFIGURATION/foo_ref_date_2020_02_02_23h_59m_59s.txt"
]#
# 1
#
find "$SEARCH_PATH" | wc -l
##                                    --> return 1911 elements
#
#
# 2
#
find "$SEARCH_PATH" \( \
        \( ! -newer "$FILE_DATE_REF_DEB" \) \
        \) -print | wc -l
# #                                    --> return 1703 elements
#
#
# 3
#
find "$SEARCH_PATH" \( \
        \( -newer "$FILE_DATE_REF_END" \) \
        \) -print | wc -l
# #                                    --> return 176 elements
#
# so between date there is 1911 (all) - 1703 (before deb) -176 ( after end) = 32 elements
#
# 4
#
find "$SEARCH_PATH" \( \
        \( -newer "$FILE_DATE_REF_DEB" ! -newer "$FILE_DATE_REF_END" \)  \
        \) -print | wc -l
# #                                    --> return 32 elements
#
# ========================================================================================
#
#
# 5
#
find "$SEARCH_PATH" \( \
        \( -newer "$FILE_DATE_REF_END" -o ! -newer "$FILE_DATE_REF_DEB" \) -prune \
        \) -o -print | wc -l
# #                                    --> return 00 elements != 1911 (all) - 1703 (before deb) -176 ( after end)
#
# ========================================================================================
#
find "$SEARCH_PATH" \( \
        \( -newer "$FILE_DATE_REF_END" -o ! -newer "$FILE_DATE_REF_DEB" \) -prune \
        \) -o -print | wc -l
# #                                    --> return correct number of elements on Chubler_XL examples
]

Any help is welcome

I guess you have a wrong perception how the pruning works.?
-prune stops descending directories at the current point.
When it is preceded by a condition that becomes true for a directory, then that directory will be skipped.
When it is preceded by a condition that becomes true for a file, then the file and following files will not be excluded, only further directories in that directory will be skipped.

Do you mean that it is useless to try to prune some folders after applying a rule based on file rule ( -newer seems to be applied on file ) ?

--- Post updated at 17:30 ---

What i need is :

find "$SEARCH_PATH" \
keep file -newer "$FILE_REF_DEB" ! -newer "$FILE_REF_END" \
exclude any files in folder which name relative to search path is exactly \( .cache   or  .mozilla or .... /etc/dir1/dir2/dir3  \)  \
exclude any files in folder which name contains partial folder name \( *properties*  or  *cache*  or ..... )

*properties* like 'view_properties' or 'properties_icons'
*cache* like 'icon_cache' or 'cache_local'

I have tried so many syntax that i don't know what to do next

Hi
maybe

find "$SEARCH_PATH"  -maxdepth 1 \( -newer "$FILE_DATE_REF_END" -o ! -newer "$FILE_DATE_REF_DEB" \)

--- Post updated at 19:52 ---

or

find "$SEARCH_PATH"/*  -prune \( -newer "$FILE_DATE_REF_END" -o ! -newer "$FILE_DATE_REF_DEB" \)

From the original post we have:

find path \( \
   \( [folder-condition A] \) -prune -o \
   \( [folder-condition B] \) -prune -o \
   \( [folder-condition C] \) -prune \
\) -o \( \
   \( [file-condition D] \) -o
   \( [file-condition E] \) \
\) -o -print

You have no folder pruning conditions and two file pruning conditions so, the find should have been:

find "$SEARCH_PATH"  \(
    -false
\) -o \( \
    \( ! -newer "$FILE_DATE_REF_DEB" \) -o
    \(  -newer "$FILE_DATE_REF_END" \)
\) -o -print

Which can be simplified to:

find "$SEARCH_PATH" \( ! -newer "$FILE_DATE_REF_DEB" -o -newer "$FILE_DATE_REF_END" \) -o -print

and further simplified to

find "$SEARCH_PATH" -newer "$FILE_DATE_REF_DEB" ! -newer "$FILE_DATE_REF_END" -print

This find is equivalent to the find from the original post which returned 32 elements.

Hope this helps you work out was is going on. Note that -prune only comes into the find when you have conditions that remove directories (and all files below them).

1 Like

Thank you for helping.
I rewrite my need.
From the original post :
I have rules that exclude folders using folder conditions, I have rules that exclude files using files conditions. That's ok.
Now during some times i have modifies files in different folders. But the folders have still the same organization. The rules on folders and files are still OK.
So keeping the general rules, I want apply the general rule between to dates specifies by a file_date_deb and a file date end.

find "$SEARCH_PATH" \   # still apply
keep file -newer "$FILE_REF_DEB" ! -newer "$FILE_REF_END" \  # fixe the date duration
then apply rules on folders      \    should still apply
then apply rules on files         \   should still apply.

that could not be :

find "$SEARCH_PATH" -newer "$FILE_DATE_REF_DEB" ! -newer "$FILE_DATE_REF_END" -print

I still need help for comprehension.