Visit Our UNIX and Linux User Community


Bash find : another problem with prune


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash find : another problem with prune
# 1  
Old 02-03-2020
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 :
Code:
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)
#
# ========================================================================================
#


Code:
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

Moderator's Comments:
Mod Comment Thanks for trying to add CODE TAGS but looks like your [CODE] was missing ] so please be careful while adding CODE TAGS to your answers/codes/samples.

Last edited by RavinderSingh13; 02-03-2020 at 07:49 AM..
# 2  
Old 02-03-2020
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.

Last edited by MadeInGermany; 02-03-2020 at 11:01 AM..
# 3  
Old 02-03-2020
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 :
Code:
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
# 4  
Old 02-03-2020
Hi
maybe
Code:
find "$SEARCH_PATH"  -maxdepth 1 \( -newer "$FILE_DATE_REF_END" -o ! -newer "$FILE_DATE_REF_DEB" \)

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

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

# 5  
Old 02-03-2020
From the original post we have:
Code:
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:
Code:
find "$SEARCH_PATH"  \(
    -false
\) -o \( \
    \( ! -newer "$FILE_DATE_REF_DEB" \) -o
    \(  -newer "$FILE_DATE_REF_END" \)
\) -o -print

Which can be simplified to:
Code:
find "$SEARCH_PATH" \( ! -newer "$FILE_DATE_REF_DEB" -o -newer "$FILE_DATE_REF_END" \) -o -print

and further simplified to
Code:
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).

Last edited by Chubler_XL; 02-03-2020 at 06:04 PM.. Reason: Work thru original conditions and simplify to get find that works.

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using prune with find

Hi, I have two files under two separate directories as in: find . -name test.sh ./test.sh ./abc/test.sh I want my find to only look for the file test.sh that is under the current directory and not one under /abc How do I use prune to achieve this? I am on AIX (3 Replies)
Discussion started by: swasid
3 Replies

2. Shell Programming and Scripting

find: -prune and -name options

I am trying to find all .rhosts files on some unix systems. I tried just -name ".rhosts" but we have a lot of really large NFS and MVFS systems that I do not want to crawl and I am having a hard time excluding them. I also need to scan more than just /root /home and /users, so I really need to scan... (1 Reply)
Discussion started by: nitrobass24
1 Replies

3. UNIX for Dummies Questions & Answers

Find with Prune not working

Hi I am trying to list all files in every subdirectory from a given location. However, I realise that 1 folder will have files that I am not interested in. This is using a .csh file to execute I have tried different scripts but to no avail. My current incarnation is below. Would someone be... (4 Replies)
Discussion started by: wonderbison
4 Replies

4. UNIX for Dummies Questions & Answers

Find prune Trash

How do I run a find without is looking in ./Trash gregg@gregg-desktop:/media/Audio$ find . -type f ! -name '*.jpg' -size 1M -print |head find: `./.Trash-1000/expunged/2781324553/mp3-to-m4b-batch': Input/output error find:... (0 Replies)
Discussion started by: glev2005
0 Replies

5. Shell Programming and Scripting

Find + prune + mtime

Hi, i try to catch all files in a dir ,without going down in subdir , which don't have file extension and older than 10 days for example: my dir : drwxr-xr-x 7 notes01 notes 4096 Mar 8 14:11 . drwxr-xr-x 116 root system 4096 Mar 9 11:17 .. -rw-r----- 1 notes01... (4 Replies)
Discussion started by: Nicol
4 Replies

6. Shell Programming and Scripting

How to use -path and -prune with find

OK, I'm trying search and destroy tabs again. This time I'm having trouble excluding certain directories from my search. Here is what I have tried and it is not ignoring the top level build directory: find . -path ./build -prune -name \*.java -o -print | xargs grep -i ' ' I don't... (6 Replies)
Discussion started by: siegfried
6 Replies

7. Shell Programming and Scripting

find with prune option

Hi, I want to list files only from the current dir and its child dir (not from child's child dir). i have the following files, ./ABC/1.log ./ABC/2.log ./ABC/ABC1/A.log ./ABC/ABC1/B.log ./ABC/ABC1/XYZ/A1.log ./ABC/ABC1/XYZ/A2.log Here i want to list only the log file from current... (1 Reply)
Discussion started by: apsprabhu
1 Replies

8. UNIX for Dummies Questions & Answers

Problem using find with prune on large number of files

Hi all; I'm having a problem when want to list a large number of files in current directory using find together with the prune option. First i used this command but it list all the files including those in sub directories: find . -name "*.dat" | xargs ls -ltr Then i modified the command... (2 Replies)
Discussion started by: ashikin_8119
2 Replies

9. UNIX for Dummies Questions & Answers

Using prune with find command

Hi, I am using a find command like below in my script: find /outfiles -type f -name cat -o -name vi -o -name grep 2>/dev/null Which will search for files like "cat" , "vi" or "grep" in the "/outfiles" and subdirectories. I want to ignore a particular subdirectory from the search. I... (4 Replies)
Discussion started by: deepakgang
4 Replies

10. UNIX for Dummies Questions & Answers

find command with prune help

I have a directory named https-abcd Under that I have some directories, files and links. One of those directories is with name logs and the logs directory has lot of files in it. I need to tar the whole https-abcd directory excluding the logs directory only, I should get all the links, files and... (2 Replies)
Discussion started by: venu_nbk
2 Replies

Featured Tech Videos