19

I'm trying to find a directory with this command:

find /users/dan/ -name 'Prams' -type d

I see a huge amount of 'No such file or directory' output. Is there a way to make find shut up if it doesn't find anything?

2
  • this worked for me: find /users/dan/ -name 'Prams' -type d | tee log Feb 25, 2012 at 1:41
  • 1
    the pipe without ampersand only outputs std output. If it was |& log, it will print those errors as well. Feb 25, 2012 at 1:42

3 Answers 3

24

Try this:

find /users/dan/ -name 'Prams' -type d 2>/dev/null
7
  • it says: find:paths must precede expression. I am running linux 2.6.9-67.0.7 Feb 25, 2012 at 1:32
  • which flavor: can you run uname -a Feb 25, 2012 at 1:38
  • Linux machine-3 2.6.9-67.0.7.ELsmp #1 SMP Wed Feb 27 04:47:23 EST 2008 x86_64 x86_64 x86_64 GNU/Linux Feb 25, 2012 at 1:40
  • this worked for me: find /users/dan/ -name 'Prams' -type d | tee log Feb 25, 2012 at 1:40
  • interesting, this didn't work for me Feb 25, 2012 at 1:42
3

You can suppress the STDERR output:

find /users/dan/ -name 'Prams' -type d 2> /dev/null

Or you can use find to show all directories and filter its output with grep:

find /users/dan -type d | grep "Prams"

The find command won't print "no such file or directory" if the search path (/users/dan, in this case) exists, even if there are no matches. Are you sure this directory exists?

0

His syntax is correct if indeed /users/dan/ < exists in the first place!

There should be no 'No such file or directory' outputs in the first place.

find $HOME -name 'Prams' -type d

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .