Yogesh
Yogesh

Reputation: 214

Unable to use "-prune" option from find command

I don't want to find "passwd" under "/etc" directory, but I do want to find rest of the "passwd", I am trying following,

sudo find / -name '/etc' -prune -o -name 'passwd' -print

this is the output I get,

/home/previous_cache/1_0_59/httpd-2.4.7/srclib/apr/passwd
/home/1_0_59/httpd-2.4.7/srclib/apr/passwd
/etc/pam.d/passwd
/etc/passwd
/etc/cron.daily/passwd
/usr/share/bash-completion/completions/passwd
/usr/share/lintian/overrides/passwd
/usr/share/doc/passwd
/usr/bin/passwd

this is the output I expect,

/home/previous_cache/1_0_59/httpd-2.4.7/srclib/apr/passwd
/home/1_0_59/httpd-2.4.7/srclib/apr/passwd
/usr/share/bash-completion/completions/passwd
/usr/share/lintian/overrides/passwd
/usr/share/doc/passwd
/usr/bin/passwd

I referred this, good info about prune, but could not solve my problem

Upvotes: 1

Views: 116

Answers (2)

SMA
SMA

Reputation: 37023

try -path instead of -name

sudo find / -path /etc -prune -o -name 'passwd' -print 

Upvotes: 0

Mithrandir
Mithrandir

Reputation: 25337

Try this:

 find / -path '/etc' -prune -o -name 'passwd' -print

Upvotes: 2

Related Questions