1

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
  • 173
  • 1
  • 3
  • 12

2 Answers2

1

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

find /usr ! \( -path '/usr/share' -prune \) -type f
oguz ismail
  • 1
  • 16
  • 47
  • 69
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
  • 204,365
  • 48
  • 270
  • 300
  • for an explanation of the "prune or print" construct, run `man find` and type `/^ *Pruning` to search for the section that describes how it works. It was too long to paste in here, but the search will take you right to it. – Life5ign Aug 17 '22 at 00:21