DXXPublic
DXXPublic

Reputation: 19

Need help omitting folders in find command

I have this line in a script I'm writing

find / \( -perm -4000 -o -perm -2000 \) -type f -exec file {} \; | grep -v ELF | cut -d":" -f1 >> $OUTPUT

It does the work, BUT I always get these messages I want to omit

find: `/proc/29527/task/29527/fd/5': No such file or directory
find: `/proc/29527/task/29527/fdinfo/5': No such file or directory
find: `/proc/29527/fd/5': No such file or directory
find: `/proc/29527/fdinfo/5': No such file or directory

How can I omit the /proc directory?

Upvotes: 1

Views: 57

Answers (3)

Rahul
Rahul

Reputation: 77866

What if you redirect STDERR to /dev/null. That way, you don't see the unwanted error/warning in your TTY (STDOUT) like

{ find / \( -perm -4000 -o -perm -2000 \) -type f -exec file {} \; | grep -v ELF | cut -d":" -f1 >> $OUTPUT; } 2>/dev/null

Upvotes: 1

David C. Rankin
David C. Rankin

Reputation: 84551

The following prunes the proc directory:

find / -name /proc -prune -o \
\( -perm -4000 -o -perm -2000 \) -type f \
-exec file {} \; | grep -v ELF | cut -d":" -f1 >> $OUTPUT

Upvotes: 0

Sean Bright
Sean Bright

Reputation: 120644

I believe this should work:

find / -path /proc -prune -o \( -perm -4000 -o -perm -2000 \) -type f ...
       ^^^^^^^^^^^^^^^^^^^^^ Add this to your command line

Upvotes: 1

Related Questions