在外壳程序中从通配符搜索中排除字符串 [英] Exclude a string from wildcard search in a shell
本文介绍了在外壳程序中从通配符搜索中排除字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从文件搜索中排除某个字符串.
I am trying to exclude a certain string from a file search.
假设我有一个文件列表:file_Michael.txt,file_Thomas.txt,file_Anne.txt.
Suppose I have a list of files: file_Michael.txt, file_Thomas.txt, file_Anne.txt.
我希望能够写类似
ls *<and not Thomas>.txt
给我file_Michael.txt和file_Anne.txt,但不给我file_Thomas.txt.
to give me file_Michael.txt and file_Anne.txt, but not file_Thomas.txt.
相反很容易:
ls *Thomas.txt
使用单个字符进行操作也很容易:
Doing it with a single character is also easy:
ls *[^s].txt
但是如何使用字符串呢?
But how to do it with a string?
塞巴斯蒂安
推荐答案
您可以使用find来做到这一点:
You can use find to do this:
$ find . -name '*.txt' -a ! -name '*Thomas.txt'
这篇关于在外壳程序中从通配符搜索中排除字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文