There is a directory under /tmp with the name test_copy.

$ ls /tmp/test_copy/
a.sh b.sh  

$ cd /tmp  
/tmp$ find . -name test_copy  
./test_copy

But if I run the following find command it does not return anything.

~/scripts$ find /tmp -name test_copy  
~/scripts$  

Why can't find find the directory in the last case?

share|improve this question
3  
What is the result of ls -ld /tmp? – xhienne 17 hours ago
2  
@xhienne: You are right! It was a symlink to another dir. Can you post it as an answer? – Jim 17 hours ago

If /tmp is a symbolic link, find won't enter the directory and will just stop, finding nothing.

On the other hand, any of the following commands will work:

find -H /tmp -name test_copy
find /tmp/ -name test_copy

(the ending / dereferences the symlink)

share|improve this answer
1  
This is likely to be the case on macOS in particular. On macOS, /tmp is a symlink to /private/tmp or some such. – kojiro 12 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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