Results 1 to 2 of 2

Thread: findutils: Ignore permission denied but Exit Status still 1

  1. #1

    Question findutils: Ignore permission denied but Exit Status still 1

    I want to do a find for files and ignore permission denied.

    My basic command is:
    find . -type f -name "*ext"
    echo $?

    I can get rid of the error message by adding:
    find . -type f -name "*ext" 2>/dev/null
    echo $?

    But, the Exit Status is 1, and not 0, which complicates automation.

    If I plug this into a script in a for loop, I make it a habit to check the exit status before proceeding. I've played around with various find options, but have not been successful in getting find to ignore permission denied. I want the command to be pretty generic. I did try putting in a user and group which shouldn't have matched, played with ands and or's and complex stmts, but find still returned with an exit status of 1. I don't want to use sudo.

    Any suggestions.

    Thank you.

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: findutils: Ignore permission denied but Exit Status stil

    If you want to always return true status, you could do something like this:

    Code:
    find . -type f -name "*ext" 2>/dev/null || true

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •