开发者

List files that don't match a string in bash

I'm a newbie in bash and I would like to pass as parameter to a python function all files in a directory that don't match a given pattern. sth. like:

$myscripts/myprog.py $myf开发者_Go百科iles/!(bonjovi)

The above example should retrieve all files that don't match to "bonjovi".

Best wishes


You have the syntax exactly right. You just need to enable it.

shopt -s extglob


It's probably easiest to use grep, xargs and a regular expression. grep -v excludes lines (in this case filenames) matching a given pattern.

ls | grep -v 'bonjovi' | xargs myscripts/myprog.py
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜