如何使用 bash 中的 find 递归过滤点文件?
我进行了广泛的搜索,但似乎找不到这个看似简单的问题的答案!
我有一个目录,其中包含一些点文件(它们恰好是 .git
但很可能是 .svn
甚至可能是其他文件)和一些非点文件。我正在寻找一个通用函数,该函数将列出该目录的所有子目录,除了以句点.
开头的子目录。
我认为这是 find 的某种变体。 -type d
但我尝试了几种咒语,但都失败了。
类似的东西
def find_files(listing, dir):
for entry in listdir(dir):
if isdir(entry) and does_not_begin_with_dot(entry):
listing.append(entry)
find_files(listing, entry)
(很惊讶没有人问这个——也许还有一种我没有看到的更猛烈的方式?)
I've searched far and wide but can't seem to find the answer to this seemingly simple question!
I have a directory that contains some dotfiles (they happen to be .git
but the could easily be .svn
and maybe even something else) and some non-dotfiles. I'm searching for a general function that will list all subdirectories of this directory, except the ones beginning with a period .
.
I'm thinking it's some variant of find . -type d
but I've tried several incantations and come up short.
Something like
def find_files(listing, dir):
for entry in listdir(dir):
if isdir(entry) and does_not_begin_with_dot(entry):
listing.append(entry)
find_files(listing, entry)
(Surprised nobody's asked this - maybe there's a more bash-ish way that I'm not seeing?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
...或...
...or...
尝试一下:
Give this a try:
我不确定这是否是您想要的,但是为了递归地列出 bash 中的所有子目录,我通常会执行类似
Works 的操作,比我尝试过的某些查找选项要快得多。缺点是使用 ls 最后会得到额外的冒号,但对我来说不是这样。
//编辑 好的,我尝试从这里找到其他答案,它们工作得相当快......但它们比 ls 更难记住。 :)
I am not sure if this is what you want, but to recursively list all subdirectories in bash I usually do something like
Works a lot faster than some find options I tried. The disadvantage is that using ls I get extra colon at the end, but that is not a case for me.
//edit Ok, I tried other find answers from here and they work quite fast... but they are harder to remember than ls. :)