免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: sywolf_cu
打印 上一主题 下一主题

[文件目录] 如何用ls和正则表达式,显示不包含某字符串的所有文件名,望高手指教 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-02-23 17:26 |显示全部楼层 |倒序浏览
如下文件,不想显示出文件名中包含2015的文件

# ls
012016.log  1.sh  11012016.log  110120160102.log  11012016_0.log  201601.log  A  B  dfqafdfa_201602032320.log  kao.log  run.log

# ls *[^2016]*.log
11012016_0.log  dfqafdfa_201602032320.log  kao.log  run.log
这样却不对

实际我想得到
1.sh A B kao.log  run.log

论坛徽章:
0
2 [报告]
发表于 2016-02-23 17:59 |显示全部楼层
不行呢,bash和csh都试过了

# ls --hide=*2016
012016.log  1.sh  11012016.log  110120160102.log  11012016_0.log  201601.log  A  B  dfqafdfa_201602032320.log  kao.log  run.log

论坛徽章:
0
3 [报告]
发表于 2016-02-23 18:07 |显示全部楼层
# type ls
ls is aliased to `ls $LS_OPTIONS'
# echo $LS_OPTIONS
-A -N --color=tty -T 0
# unalias ls
# type ls
ls is hashed (/bin/ls)

# ls --hide=*2016
012016.log  1.sh  11012016.log  110120160102.log  11012016_0.log  201601.log  A  B  dfqafdfa_201602032320.log  kao.log  run.log

论坛徽章:
0
4 [报告]
发表于 2016-02-23 18:12 |显示全部楼层
有没有不用grep的方法回复 6# moperyblue


   

论坛徽章:
0
5 [报告]
发表于 2016-02-23 18:14 |显示全部楼层
是在什么sh下?测试bash和csh不行
# ls !(*2016*)
-bash: !: event not found

# ls !(*2016*)
Badly placed ()'s.
回复 3# cao627


   

论坛徽章:
0
6 [报告]
发表于 2016-02-24 14:12 |显示全部楼层
去掉alias也试过了,贴在5楼了
回复 10# aweAll


   

论坛徽章:
0
7 [报告]
发表于 2016-02-24 14:12 |显示全部楼层
bash下测试OK,多谢大神!
多问一句,如果是csh或ksh呢?
回复 12# blackold


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP