bash 如何在 osx 上 ls --ignore

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11213849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 02:36:49  来源:igfitidea点击:

How to ls --ignore on osx

macosbashls

提问by hoss

I'm trying to do the following on OSX:

我正在尝试在 OSX 上执行以下操作:

ls -lR --ignore *.app

ls -lR --ignore *.app

So that I can recursively search through all folders exceptfor .app folders.

这样我就可以递归搜索.app 文件夹之外的所有文件夹。

However it seems there is seems to be no --ignoreor --hideoptions in Darwin.

然而,达尔文似乎没有--ignore或没有--hide选择。

Perhaps a script to recursively search one folder deep for a given set and I'm not sure I cant pipe ls -lRthrough anything because of the format of the output:

也许是一个脚本,用于递归搜索给定集合的一个文件夹深处,但ls -lR由于输出的格式,我不确定我无法通过任何管道:

./ROOT/Applications/Some_app:
drwxr-xr-x   3 admin  root  102 26 Jun 11:03 app-bundle.app  #<- WANT THIS
drwxr-xr-x@ 24 admin  root  816 26 Jun 11:24 folder          #<- WANT THIS

./ROOT/Applications/Some_app/app-bundle.app:                 #<- DON'T WANT
drwxr-xr-x  7 admin  root  238 26 Jun 11:03 Contents         #<- DON'T WANT
...

采纳答案by Rob Napier

Use find:

使用find

find . -ls -name '*.app' -prune

回答by jordanm

In bash, you can use extended globbing to exclude a pattern.

在 bash 中,您可以使用扩展的通配符来排除模式。

shopt -s extglob # this must be on its own line
echo !(*.app) # match everything except for the given pattern

If you have bash version 4 or higher, you can use globstar to do this recursively.

如果您有 bash 版本 4 或更高版本,您可以使用 globstar 递归执行此操作。

shopt -s globstar
shopt -s extglob 
echo **/!(*.app) 

回答by Oath

An alternative is to pipe to grep:

另一种方法是通过管道连接到 grep:

ls | grep -v

ls | grep -v