How to only find files in a given directory, and ignore subdirectories using bash

后端 未结 5 589
礼貌的吻别
礼貌的吻别 2021-01-30 05:45

I\'m running the find command to find certain files, but some files in sub-directories have the same name which I want to ignore.

I\'m interested in files/pa

5条回答
  •  温柔的废话
    2021-01-30 06:40

    I got here with a bit more general problem - I wanted to find files in directories matching pattern but not in their subdirectories.

    My solution (assuming we're looking for all cpp files living directly in arch directories):

    find . -path "*/arch/*/*" -prune -o -path "*/arch/*.cpp" -print

    I couldn't use maxdepth since it limited search in the first place, and didn't know names of subdirectories that I wanted to exclude.

提交回复
热议问题