Exclude a sub-directory using find

前端 未结 6 1869
鱼传尺愫
鱼传尺愫 2021-01-30 18:54

I have directory structure like this

data
|___
   |
   abc
    |____incoming
   def
    |____incoming
    |____processed
   123
    |___incoming
   456
    |___i         


        
6条回答
  •  清酒与你
    2021-01-30 19:51

    Just for the sake of documentation: You might have to dig deeper as there are many search'n'skip constellations (like I had to). It might turn out that prune is your friend while -not -path won't do what you expect.

    So this is a valuable example of 15 find examples that exclude directories:

    http://www.theunixschool.com/2012/07/find-command-15-examples-to-exclude.html

    To link to the initial question, excluding finally worked for me like this:

    find . -regex-type posix-extended -regex ".*def/incoming.*|.*456/incoming.*" -prune -o -print 
    

    Then, if you wish to find one file and still exclude pathes, just add | grep myFile.txt.

    It may depend also on your find version. I see:

    $ find -version
    GNU find version 4.2.27
    Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION SELINUX
    

提交回复
热议问题