0

I want to find all files in /usr/ but not in /usr/share

from this post Exclude a sub-directory using find I tried:

find /usr -type f -not -path /usr/share -print

-> print files from /usr/share

from this post How to exclude a directory in find . command I tried:

find /usr -path /usr/share -prune -print 

->outputs nothing altough there are files in /usr/bin

I also tried:

find /usr -path ! /usr/share -type f -print 

-> outputs an error

achille
  • 159
  • 1
  • 2
  • 10

2 Answers2

0

Drop -print and negate -path ... -prune:

find /usr ! \( -path '/usr/share' -prune \) -type f
oguz ismail
  • 39,105
  • 12
  • 41
  • 62
0

By default, a boolean and is used to join operators and primaries. So find /usr -path /usr/share -prune -print is equvialent to find /usr -path /usr/share -prune -a -print. But you want to print things that are not pruned. So use:

find /usr -path /usr/share -prune -o -print

If you want to limit the search to regular files:

find /usr -path /usr/share -prune -o -type f -print
William Pursell
  • 190,037
  • 45
  • 260
  • 285