2

I am trying to use prune as:

find /opt/app/bss/sieb/fs_clone1/userpref -name "*" -type f -mtime -7 -prune

This is still searching sub-directories.

2

It's still searching sub-directories because you're not -pruning any.

To -prune a find tree you must first match it.

find / -type d ! -path / -prune -print

/boot
/home
/mnt
/opt
/esp
/dev
/proc
/root
/run
/srv
/sys
/tmp
/usr
/var
/etc

I had to use -path / because otherwise the first directory found would have been / the root and it would be -prune'd then -printed.

But as you can see, it is the matched files that are -pruned and nothing else. So if you match -type f you won't -prune any trees at all - regular files have no subdirectories.

You probably want something like:

find /opt/app/bss/sieb/fs_clone1/userpref \
     -path \*path/to/ignore -prune -o     \
   ! -type d -mtime -7

This is very different than your statement. In the first place -path path/to/ignore doesn't work. It has to match a whole path, and your start tree starts with / but path/to/ignore doesn't at all. So I put * globstar in, but better - and probably more succinct could be:

cd /opt/app/bss/sieb/fs_clone1/userpref &&
find . -path ./path/to/ignore -prune -o  \
     ! -type d -mtime 7

...which would make your output a lot less messy. Either way, though, the all paths matched by the -path pattern will be -prune'd then not printed because we -o away to another statement and it is only the last expression of the entire find script that is autoprinted.

The last part is also different, though. I dropped -name '*' because all names match '*' and so you might as well just not filter on that. And the ! -type d is what I've found a lot of people often mean when they say -type f. The former matches any file type which is not a directory - to include fifos and sockets and the rest of the weird ones. The latter matches only regular files. It maybe you really do want the latter - but I just thought I'd mention it.

Anyway, when all is said and done the *path/to/ignore is matched, pruned, and not printed, then, of everything else, files which are not type directory and which were modified 7 days ago.

1
find /opt/app/bss/sieb/fs_clone1/userpref -type f -mtime -7 -path path/to/ignore -prune -o -print

But I think what you need is -depth.

Note that −maxdepth 0 means only apply the tests and actions to the command line arguments. −mindepth 1 means process all files except the command line arguments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.