shopt extglob与ls

    前一阵子,与一个程序员交流,问一个linux的问题,如果使用ls命令仅仅显示当前
目录不包括.的文件.

我以前常用的做法是ls加grep过滤的方式,我想这个也是许多linux用户常见的操作模式.
ls -l | grep -v '\.'

在他看来linux没有windows灵活,windows下仅仅dir *.就可以了.而且ls的命令参数如此
之多,竟然无法实现.

我当时给他的答案是windows下关于*的理解与linux不一样.出于好奇,我还是看了ls的文档,
我发现执行ls --ignore=*.* -l 可以做到.
后来我有看了bash shell编程的文档,发现在打开extglob模式下(缺省是打开的),ls也可以实现,而且更加灵活.

shopt -u extglob #关闭
shopt -s extglob #打开

ls -l !(*.*)
ls -l -d !(*.*)

把bash shell手册摘录如下:
If  the  extglob shell option is enabled using the shopt builtin, several extended
pattern matching operators are recognized.  In the following description, a pattern-
list is a list of one or more patterns separated by a |.  Composite patterns may be
formed using one or more of the following sub-patterns:

?(pattern-list) Matches zero or one occurrence of the given patterns
*(pattern-list) Matches zero or more occurrences of the given patterns
+(pattern-list) Matches one or more occurrences of the given patterns
@(pattern-list) Matches exactly one of the given patterns
!(pattern-list) Matches anything except one of the given patterns

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-695533/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/267265/viewspace-695533/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值