Thread: find commnad

    #1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Orlando FL
    Posts
    130
    Rep Power
    12

    find commnad


    Hello,
    Anyone knows how to suppress the msg from a 'find'command that said:

    find: cannot read dir /lost+found: Permission denied
    ???
    Help me, help you, help others...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    you could use
    find ....... |grep -v "cannot read dir /lost+found: Permission denied"

    or if you want to suppress all error messages use
    find ...... 2>/dev/null
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Orlando FL
    Posts
    130
    Rep Power
    12
    Hi, thanks for writing. Sorry I was out for a while and now I am back. Anyway, I tried your tips but still doesn't work.

    MY ORIGINAL PROBLEM/QUESTION STARTED LIKE THIS:
    tiger[zdeng]% find / -name 'bin'
    find: cannot read dir /lost+found: Permission denied
    find: cannot read dir /usr/lost+found: Permission denied
    /usr/lib/lp/bin
    /usr/sadm/lib/smc/bin
    ^C


    THE GREP SOLUTION:
    tiger[zdeng]% find / -name 'bin' |grep -v 'find: cannot read dir /lost+found'
    find: cannot read dir /lost+found: Permission denied
    find: cannot read dir /usr/lost+found: Permission denied
    ^C

    THE STD ERROR REDIRECT SOLUTION:
    tiger[zdeng]% find / -name 'bin' 2> /dev/null
    find: bad option 2
    find: path-list predicate-list

    I am using tcsh as shell. More suggestion?
    Help me, help you, help others...
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    yes

    for the grep - it could not work since find does write the errors to stderr.
    so it has to be:

    find / -name 'bin' 2>&1 |grep -v 'find: cannot read dir /lost+found'

    The redirection would work in bash. for tcsh, use:

    find / -name 'bin' |& grep -v 'find: cannot read dir /lost+found'

    to suppress all error messages, you need to switch shells as tcsh cannot redirect stderr only.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Orlando FL
    Posts
    130
    Rep Power
    12
    So the trick is redirect std error to std out so grep can see... yeah works great! You are the best! thx ;-)
    Help me, help you, help others...
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    1
    Rep Power
    0
    This command is for use in bash shell, not tcsh:

    find / -name 'bin' 2>/dev/null
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    190
    Originally posted by ryofnott
    This command is for use in bash shell, not tcsh:

    find / -name 'bin' 2>/dev/null
    Ok, kids: What does the author want to tell us? Read between the lines!

    He clearly states that redirecting stderr to stdout is an act of oppression against harmless processes done by agressive forces straight from (s)hell.

    Eat your supper, or you'll all be doomed!

    ...M
    Last edited by M.Hirsch; November 6th, 2003 at 03:10 PM.

IMN logo majestic logo threadwatch logo seochat tools logo