Linux终端中的文件全局模​​式 [英] File Glob Patterns in Linux terminal

查看:59
本文介绍了Linux终端中的文件全局模​​式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想搜索一个可能包含 kavi kabhi 的文件名. 我在终端上写了命令:

I want to search a filename which may contain kavi or kabhi. I wrote command in the terminal:

ls -l *ka[vbh]i*

ka i 之间,可能存在 v bh .

Between ka and i there may be v or bh .

我编写的代码不正确.正确的命令是什么?

The code I wrote isn't correct. What would be the correct command?

推荐答案

执行此操作的一种好方法是使用扩展的glob.有了它们,您可以在Bash上执行正则表达式.

A nice way to do this is to use extended globs. With them, you can perform regular expressions on Bash.

要启动,您必须启用extglob功能,因为默认情况下它已禁用:

To start you have to enable the extglob feature, since it is disabled by default:

shopt -s extglob

然后,编写具有以下条件的正则表达式:stuff + ka + vbh + i + stuff.在一起:

Then, write a regex with the required condition: stuff + ka + either v or bh + i + stuff. All together:

ls -l *ka@(v|bh)i*

语法与常规正则表达式略有不同,因此您需要阅读扩展的globs 那...

The syntax is a bit different from the normal regular expressions, so you need to read in Extended Globs that...

@(列表):匹配给定的模式之一.

@(list): Matches one of the given patterns.

测试

$ ls
a.php  AABB  AAkabhiBB  AAkabiBB  AAkaviBB  s.sh
$ ls *ka@(v|bh)i*
AAkabhiBB  AAkaviBB

这篇关于Linux终端中的文件全局模​​式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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