When I want to find a file I use the command find <directory> -name <filename>
. Often the command will output multiple lines with "Permission Denied" at the end. Is there a way to filter the results to exclude these lines?
Asked
Active
Viewed 387 times
1

gkeenley
- 6,088
- 8
- 54
- 129
-
1`find ... 2> /dev/null` maybe? – Mark Setchell Sep 09 '19 at 20:59
-
2Possible duplicate of [How can I exclude all "permission denied" messages from "find"?](https://stackoverflow.com/questions/762348/how-can-i-exclude-all-permission-denied-messages-from-find) – Arkadiusz Drabczyk Sep 09 '19 at 21:16
1 Answers
1
This will work
find <directory> -name <filename> 2>/dev/null
Example
[test@satellite ~]$ find / -name test
find: ‘/boot/grub2’: Permission denied
find: ‘/proc/tty/driver’: Permission denied
find: ‘/proc/1/task/1/fd’: Permission denied
find: ‘/proc/1/task/1/fdinfo’: Permission denied
find: ‘/proc/1/task/1/ns’: Permission denied
When 2>/dev/null
is used
[test@satellite ~]$ find / -name test 2>/dev/null
/var/spool/mail/test
/usr/bin/test
/usr/lib64/python2.7/test
/usr/lib64/python2.7/site-packages/OpenSSL/test
/usr/lib64/python2.7/unittest/test
/usr/share/doc/jsr-305-0/sampleUses/test

Avinash Yadav
- 781
- 7
- 13