使用 ls 列出所有与模式不匹配的文件 [英] List all files that do not match pattern using ls
问题描述
可能的重复:
如何才能在 unix/linux shell 中进行模式匹配时,我使用反向通配符还是负通配符?
我已经阅读了 ls
的 man
页面,但我找不到列出所有不匹配的选项文件选择器.您知道如何执行此操作吗?
I've read the man
page for ls
, and I can't find the option to list all that do not match the file selector. Do you know how to perform this operation?
例如:假设我的目录是这样的:
For example: lets say my directory is this:
> ls
a.txt b.mkv c.txt d.mp3 e.flv
现在我想做以下事情
> ls -[SOME_OPTION] *.txt
b.mkv d.mp3 e.flv
有这样的选择吗?
如果没有,有没有办法将 ls
的输出通过管道传输到另一个只显示我想要的函数(可能是 sed
)?
If not, is there a way to pipe the output of ls
to another function (possibly sed
) that shows only the ones that I would like?
我不知道该怎么做,但我想它会是这样的:
I don't know exactly how to do this, but I'm imagining it would be something like:
> ls | sed [SOMETHING]
我真的应该学习如何使用 sed
、awk
和 grep
,但我一直在理解如何编写正则表达式.我清楚地理解正则表达式的概念,但我对使用不同语法的正则表达式感到困惑.
I really should learn how to use sed
,awk
,and grep
, but I keep getting stuck at understanding how to write the regexes. I understand the concept of regular expressions clearly, but I get confused between regexes that use different syntax.
任何帮助将不胜感激!
我忘了提到我正在运行 Mac OS X,所以这些功能可能与 unix/linux shell 的其他答案中讨论的功能略有不同(因此我对 sed
有一些困惑),awk
, 和 grep
).
I forgot to mention that I am running Mac OS X, so the functions may be slightly different from the ones discussed in other answers for the unix/linux shell (hence some of my confusion with sed
,awk
,and grep
).
推荐答案
也许这个命令对你有帮助
maybe this command will help you
find ./ -maxdepth 1 ! -path "*txt"
这篇关于使用 ls 列出所有与模式不匹配的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!