2019-04-08

笔记

  • grep 过滤 在文件中进行查找

[root@lds ~]# grep -n ‘IPV6' /etc/sysconfig/network-scripts/ifcfg-ens33

vim 编辑文件 /oldboy
[root@oldboyedu59 ~]# alias grep
alias grep='grep --color=auto' #centos 7下面 默认就有 CentOS6 5需要手动配置

-n 显示行号和内容
grep 'ssh' /tmp/vim.log
grep -n 'ssh' /tmp/vim.log

  • -w 按照单词进行过滤
[root@oldboyedu59 ~]# grep -w  '22'  /tmp/vim.log 
ssh             22/tcp                          # The Secure Shell (SSH) Protocol
ssh             22/udp                          # The Secure Shell (SSH) Protocol
ssh             22/sctp                 # SSH
c1222-acse      1153/tcp                # ANSI C12.22 Port
c1222-acse      1153/udp                # ANSI C12.22 Port
[root@oldboyedu59 ~]# grep -w  'ssh'  /tmp/vim.log 
ssh             22/tcp                          # The Secure Shell (SSH) Protocol
ssh             22/udp                          # The Secure Shell (SSH) Protocol
x11-ssh-offset  6010/tcp                        # SSH X11 forwarding offset
ssh             22/sctp                 # SSH
netconf-ssh     830/tcp                 # NETCONF over SSH
netconf-ssh     830/udp                 # NETCONF over SSH
sdo-ssh         3897/tcp                # Simple Distributed Objects over SSH
sdo-ssh         3897/udp                # Simple Distributed Objects over SSH
tl1-ssh         6252/tcp                # TL1 over SSH
tl1-ssh         6252/udp                # TL1 over SSH
ssh-mgmt        17235/tcp               # SSH Tectia Manager
ssh-mgmt        17235/udp               # SSH Tectia Manager
  • -i ignore-case 过滤的时候忽略大小写
    在文件中查找出包含ipaddr的行
[root@oldboyedu59 ~]# grep 'ipaddr' /tmp/vim.log
[root@oldboyedu59 ~]# grep -i 'ipaddr' /tmp/vim.log
IPADDR=10.0.0.201
  • grep 排除/取反 -v
    我想找出不包含#的行

grep小结:

-n 显示行号和内容
-i 不区分大小写
-v 取反或排除
-w 按照单词进行过滤

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容