0

As all we know, we can search a file or directory in the linux by:

find / -name theName

But there shows all the files and directories and permission denied, like this bellow:

...
find: /Library/Caches/com.apple.iconservices.store: Permission denied
/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django
/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/forms/jinja2/django
/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/forms/templates/django
find: /Library/SystemMigration/History/Migration-389D835B-414A-4D8D-A683-7407624E87E8/QuarantineRoot/System/Library/DirectoryServices/DefaultLocalDB/Default: Permission denied
find: /private/etc/cups/certs: Permission denied
find: /private/var/agentx: Permission denied
...

If I just want to shows the directories find by the command, how to do with it?

lustre
  • 317

1 Answers1

4

You should use

find / -type d -name theName

to only find directories whose names are theName. Without -type d you will also test the name against regular files, sockets, named pipes etc. that are not directories.

This will still give you the same "Permission denied" errors, because you don't have sufficient permissions to enter those directories.

To ignore the errors, simply add 2>/dev/null at the end of the command. This will redirect the error stream to /dev/null (they will be thrown away).

Root probably has access to the directories that you can't get into, so if you have sudo access, you could try

sudo find / -type d -name theName

This will run the find command as the root user.

Kusalananda
  • 333,661
  • And there is a requirement, I don't want to show the permission denied, because they are too many, how to solve it? – lustre Sep 10 '17 at 14:22
  • @lustre As I said, add 2>/dev/null after the command: find / -type d -name theName 2>/dev/null – Kusalananda Sep 10 '17 at 14:24