0

Using "jbossapp" user I'm using this command to find ".stat" files which are created more than 3 minutes.

find /opt/jboss/* -mmin +3 -name "*.stat" 

Recently there is a folder created in /opt/jboss/ directory with root user now while using this command I'm getting 'permission denied' from the particular folder which is interrupting the search how do I exclude the particular folder which is having root privileges.

1

Use

find /opt/jboss/* -type f -mmin +3 -name "*.stat" 2>/dev/null

The 2>/dev/null will redirect the Standard Error Output to special file /dev/null to avoid displaying any errors.

Also we add -type f to look for fIles only.

To excluding a directory use like below

find /opt/jboss/* -path /path/to/exclude -prune -o -type f -mmin +3 -name "*.stat" 2>/dev/null

also you can use -not -path as well.

find /opt/jboss/* -not -path /path/to/exclude -type f -mmin +3 -name "*.stat" 2>/dev/null

Even if you want exclude the find result from users who owned by root, use as follow:

find . \! -user root   ..... 
  • 1
    Hi AFSHIN, i have been struggling for this solution from 4 days .. there is no enough word Thanks . But Thank you so much – Kumar Aug 13 '17 at 5:34
0

If you want to exclude folders owned by root, then prune them with find:

find /opt/jboss/. \
   -type d ! -name . -owner root -prune -o -type f -mmin +3 -name '*.stat' -print

To be read as: Inside the top directory /opt/joss/ any folder that is not named ".", owned by "root" is not to be followed into. For everything else, we further constrain by picking regular files, older than 3 minutes, with extension ".stat" are to be printed to stdout.

  • Thanks for the solution i tried i m getting below error find: unknown predicate `-owner' – Kumar Aug 14 '17 at 2:25
  • @Kumar Change -owner to -user. Thanks, – user218374 Aug 14 '17 at 4:50

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.