linux通配符与正则表达式
通配符
正则表达式
[root@hadoop-bigdata01 test]# touch aa
[root@hadoop-bigdata01 test]# touch aab aabb
[root@hadoop-bigdata01 test]# ll
total 0
-rw-r--r-- 1 root root 0 May 16 19:47 aa
-rw-r--r-- 1 root root 0 May 16 19:47 aab
-rw-r--r-- 1 root root 0 May 16 19:47 aabb
[root@hadoop-bigdata01 test]# ls aa
aa
[root@hadoop-bigdata01 test]# ls aa?
aab
[root@hadoop-bigdata01 test]# ls aa*
aa aab aabb


正则表达式标准字符

[root@hadoop-bigdata01 test]# grep "1" /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
wang:x:501:501::/home/wang:/bin/bash
[root@hadoop-bigdata01 test]# grep '[0-9][0-9][0-9]' /etc/passwd
games:x:12:100:games:/usr/games:/sbin/nologin
usbmuxd:x:113:113:usbmuxd user:/:/sbin/nologin
rtkit:x:499:497:RealtimeKit:/proc:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
saslauth:x:498:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologin
pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
liucheng:x:500:500::/home/liucheng:/bin/bash
wang:x:501:501::/home/wang:/bin/bas
[root@hadoop-bigdata01 test]# grep '^r.*n$' /etc/passwd
rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin
rtkit:x:499:497:RealtimeKit:/proc:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
[root@hadoop-bigdata01 test]# ifconfig | grep 'inet addr:'
inet addr:192.168.126.191 Bcast:192.168.126.255 Mask:255.255.255.0
inet addr:127.0.0.1 Mask:255.0.0.0
[root@hadoop-bigdata01 test]#
[root@hadoop-bigdata01 test]# ifconfig | grep 'inet addr:' | grep -v '127.0.0.1'
inet addr:192.168.126.191 Bcast:192.168.126.255 Mask:255.255.255.0
[root@hadoop-bigdata01 test]# ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | sed 's/inet addr://g'
192.168.126.191 Bcast:192.168.126.255 Mask:255.255.255.0
[root@hadoop-bigdata01 test]# ifconfig | grep 'inet addr:' | grep -v '127.0.0.1' | sed 's/inet addr://g' | sed 's/Bcast.*//g'
192.168.126.191
误区
[root@hadoop-bigdata01 test]# touch ac aac abc abbc
[root@hadoop-bigdata01 test]# ll
total 0
-rw-r--r-- 1 root root 0 May 16 19:55 aac
-rw-r--r-- 1 root root 0 May 16 19:55 abbc
-rw-r--r-- 1 root root 0 May 16 19:55 abc
-rw-r--r-- 1 root root 0 May 16 19:55 ac
[root@hadoop-bigdata01 test]# ls | grep 'a*c'
aac
abbc
abc
ac
[root@hadoop-bigdata01 test]# ls | grep 'a.*c'
aac
abbc
abc
ac
[root@hadoop-bigdata01 test]# ls | grep '^a.*c'
aac
abbc
abc
ac
[root@hadoop-bigdata01 test]# ls | grep '^a*c'
aac
ac
[root@hadoop-bigdata01 test]# ls
a aac abb abbc abc ac b bb c cb
[root@hadoop-bigdata01 test]# ls | grep 'a*b'
abb
abbc
abc
b
bb
cb
这里grep 'a*b' 指的可不是含有a和b 而是a重复0次或者多次然后含有b
linux通配符与正则表达式的更多相关文章
- linux 通配符与正则表达式
linux通配符和三剑客(grep.awk.sed)正则表达式是不一样的 通配符一般用户命令行bash环境,而linux正则表达式用于awk.grep.sed
- linux中的通配符与正则表达式
在linux中,有通配符及正则表达式,那么什么是通配符和正则表达式,什么时候用? 通配符 它是由shell解析,并且一般用于匹配文件名,实际上就是shell解释器去解析的特殊符号,linux系统通 ...
- Linux通配符与基础正则表达式、扩展正则表达式
在Linux命令行操作或者SHELL编程中总是容易混淆一些特殊字符的使用,比如元字符‘*’号,作为通配符匹配文件名时表示0个到无穷多个任意字符.而作为正则表达式匹配字符串时,表示重复0个到无穷多个的前 ...
- [转帖]Linux教程(13)- Linux中的通配符和正则表达式
Linux教程(13)- Linux中的通配符和正则表达式 2018-08-22 06:16:44 钱婷婷 阅读数 39更多 分类专栏: Linux教程与操作 Linux教程与使用 版权声明:本文 ...
- linux通配符,grep和 egrep区别
其实主要是正则表达式中的一些特殊语法.在网上找的几篇文章,截取相关部分贴在了下面,方便以后翻阅. 参考:http://hi.baidu.com/sei_zhouyu/item/c18e1a950d2e ...
- linux通配符知识
注意:linux通配符和三剑客(grep,awk,sed)正则表达式是不一样的,因此,代表的意义也是有较大区别的. 通配符一般用户命令行bash环境,而linux正则表达式用于grep,sed,awk ...
- 通配符、正则表达式、python去重
1.linux通配符 *:代表所有字符(0到多个); ?:代表一个字符; ;:连续不同命令之间的分隔符; #:配置文件注释; |:管道; ~:当前用户的家目录; -:上一次所在的路径; $:变量前面需 ...
- Linux通配符知识深度实践详解
注意:linux通配符和三剑客(grep.awk.sed)正则表达式是不一样的,因此,代表的意义也有较大的区别. 通配符一般用户命令行bash环境,而Linux正则表达式用于grep.sed.awk场 ...
- bash通配符 shell正则表达式
在linux中 通配符是系统命令使用,一般用来匹配文件名或者什么的用在系统命令中. 通配符是系统级别的,通配符多用在文件名上,比如查找find,ls,cp,rm 正则表达式是操作字符串,以行尾单位来匹 ...
随机推荐
- 老李秘技:loadrunner回放脚本错误提示Error: "HTTP Status-Code 500"
老李秘技:loadrunner回放脚本错误提示Error: "HTTP Status-Code 500" 当脚本回放的时候出现错误提示Error: "HTTP Sta ...
- 修改数据库用户名--CMD环境执行有效
--CMD环境执行有效 --修改数据库用户名 select * from user$ where name='aa'; update user$ set name='bb' where name ...
- JavaScript定时器分析
一.事件循环 JavaScript是单线程,同一个时间只能做一件事情,所以执行任务需要排队.如果前一个耗时很长,那么下一个只能等待. 1)两种任务 为了更好的处理任务,JavaScript语言的设计者 ...
- 函数求值(swust oj0274)
函数求值(0274) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 1767 Accepted: 324 Accepted 14级卓 ...
- html列表问题
HTML无序列表 无序列表是一个项目的列表,此列项目运用粗体圆点(典型的小黑圆圈)进行符号. 无序列表运用 标签 Coffee Milk 浏览器闪现如下: <ul "="&q ...
- 微信小程序获取html内容后展示(C#)
使用场景:微信小程序 具体功能:从服务器获取文章内容 展示在小程序里 使用语言: C# -------------------------------------------------------- ...
- 日历上添加活动通知(Asp.net)
<div id="calendar_contain"> </div> <script language="javascript" ...
- 关于css禁止文本复制属性
最近在做DHTMLX框架替换,新框架dhx的grid是不能选中内容复制的 虽然相对来说是安全些的,但是客户体验度一定会大打折扣 网页上禁止复制主要靠JavaScript来实现.<BODY onc ...
- 论.net平台的切身感触(惑)
这篇博客只是作者客观看法,不喜勿喷,条条大路通罗马,路不同风景也不一样,接下来的路该怎么走? 简介:作者.net程序员一枚,工作已有四年,接触过.net平台winform,webform,mvc的开发 ...
- Web 网站服务
Apache 简介 Apache HTTP Server(简称Apache)是开放源码的网页服务器,基于标准的HTTP网站协议提供网页浏览服务,在Web服务器领域中长期保持着超过半数的份额.Apach ...