如何找到不与在bash给定的preFIX开头的所有文件? [英] How do I find all files that do not begin with a given prefix in bash?

查看:115
本文介绍了如何找到不与在bash给定的preFIX开头的所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹在一堆文件:

  FOO_1
FOO_2
foo_3
bar_1
bar_2
buzz_1
...

我想找到所有的文件不开始用给定的preFIX和列表保存到一个文本文件中。下面是该文件的例子做有一个给定的preFIX:

 找到bar_ *> Positives.txt


解决方案

这应该做的伎俩在任何shell

  LS | grep的-v'^ preFIX

-v选项的grep反转的搜索逻辑,使得它过滤掉所有的比赛。
用grep,而不是发现你可以使用,而不是有限的glob模式,强大的正前pressions。

I have a bunch of files in a folder:

foo_1 
foo_2
foo_3
bar_1
bar_2
buzz_1
...

I want to find all the files that do not start with a given prefix and save the list to a text file. Here is an example for the files that do have a given prefix:

find bar_* > Positives.txt

解决方案

This should do the trick in any shell

ls | grep -v '^prefix'

The -v option inverts grep's search logic, making it filter out all matches. Using grep instead of find you can use powerful regular expressions instead of the limited glob patterns.

这篇关于如何找到不与在bash给定的preFIX开头的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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