使用ls列出所有与模式不匹配的文件 [英] List all files that do not match pattern using ls

查看:427
本文介绍了使用ls列出所有与模式不匹配的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何在Unix/Linux Shell中进行模式匹配时,我使用反通配符还是负通配符?

Possible Duplicate:
How can I use inverse or negative wildcards when pattern matching in a unix/linux shell?

我已经阅读了lsman页,但找不到列出与文件选择器匹配的所有选项.您知道如何执行此操作吗?

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] 

我确实应该学习如何使用sedawkgrep,但是我一直陷于理解如何编写正则表达式的困境.我清楚地了解了正则表达式的概念,但是我对使用不同语法的正则表达式感到困惑.

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的其他答案中讨论的功能稍有不同(因此,我对sedawk,和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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆