Aalexander
Aalexander

Reputation: 5004

Exclude specific path from find's output

I searched inside my filesystem for files with a specific extension using find

find / -type f -name "*.click" 2>/dev/null

In my result I get a lot of files in a specific path which are not interesting for me like

/home/x/Dokumente/click/etc/samplepackage/test.click
/home/x/Dokumente/click/apps/csclient/test.click
/home/x/Dokumente/click/conf/test-device.click
/home/x/Dokumente/click/conf/ip6ndadvertiser.click
/home/x/Dokumente/click/conf/script-parabolawave.click
/home/x/Dokumente/click/conf/fake-iprouter.click
/home/x/Dokumente/click/conf/fromhost-tunnel.click
/home/x/Dokumente/click/conf/simple-dsdv-userlevel.click
/home/x/Dokumente/click/conf/sampler.click
/home/x/Dokumente/click/conf/script-trianglewave.click
/home/x/Dokumente/click/conf/script-squarewave.click
/home/x/Dokumente/click/conf/fastudpsrc.click
/home/x/Dokumente/click/conf/schedorder1.click
/home/x/Dokumente/click/conf/test-ping-userlevel.click
/home/x/Dokumente/click/conf/test-tcp.click
/home/x/Dokumente/click/conf/delay.click
/home/x/Dokumente/click/conf/icmp6error.click
/home/x/Dokumente/click/conf/webgen.click
/home/x/Dokumente/click/conf/test2.click
/home/x/Dokumente/click/conf/grid.click
/home/x/Dokumente/click/conf/thomer-nat.click
/home/x/Dokumente/click/conf/gnat02.click
/home/x/Dokumente/click/conf/test-clicky.click
/home/x/Dokumente/click/conf/ip64-nat3.click
/home/x/Dokumente/click/conf/mazu-nat.click
/home/x/Dokumente/click/conf/ip6print.click
/home/x/Dokumente/click/conf/gnat01.click
/home/x/Dokumente/click/conf/ip601.click

In this article I found an answer and tried like this below

find / -type f -name "*.click" -not -path "./home/ipg7/Dokumente/click/conf"  2>/dev/null

But it doesn't work I still get the output as before.

So how can I exclude a specific path and also write all the permission denied to /dev/null?

Upvotes: 0

Views: 47

Answers (2)

Tarmo
Tarmo

Reputation: 4762

You've added -not -path "./home/ipg7/Dokumente/click/conf" which does not match anything in your output due to

  1. starting with a dot,
  2. missing the pattern that matches the file part

Try -not -path "/home/ipg7/Dokumente/click/conf/*" instead

Upvotes: 1

anubhava
anubhava

Reputation: 785146

You have to use globbing in path to ignore all matches from a given path and use 2>/dev/null to ignore error:

find / -type f -name "*.click" -not -path "./home/ipg7/Dokumente/click/conf/*" 2>/dev/null

Upvotes: 1

Related Questions