标签:
1:将/etc/passwd中有root字符的行显示出来
1 [root@bogon zkero]# grep -n ‘root‘ /etc/passwd 2 1:root:x:0:0:root:/root:/bin/bash 3 11:operator:x:11:0:operator:/root:/sbin/nologin
2:指定文件(test1)中读取hello 无论大小写的行
1 [root@bogon zkero]# grep -in ‘hello‘ test1 2 1:hello 3 3:HELLO
说明:grep 中‘hello’中的‘hello‘大小写也是忽略的
3:定位符的使用^
/etc/passwd 中只显示首次出现root的行
1 [root@bogon zkero]# grep -n ‘root‘ /etc/passwd 2 1:root:x:0:0:root:/root:/bin/bash 3 11:operator:x:11:0:operator:/root:/sbin/nologin 4 [root@bogon zkero]# grep -n ‘^root‘ /etc/passwd 5 1:root:x:0:0:root:/root:/bin/bash
^在[ ]之内是反向选择,在[ ]之外是定位符
4:显示行尾字符所在行
1 [root@bogon zkero]# grep -n ‘bash$‘ /etc/passwd 2 1:root:x:0:0:root:/root:/bin/bash 3 34:zkero:x:500:500:zkero:/home/zkero:/bin/bash
5:定位显示空白行
1 [root@bogon zkero]# cat -n test1 2 1 hello 3 2 world 4 3 HELLO 5 4 6 5 WORLD 7 6 8 7 i an supker 9 8 i like computer! 10 9 11 [root@bogon zkero]# grep -n ‘^$‘ test1 12 4: 13 6: 14 9:
6:一般脚本文件都有空白行和#注释开头的行,如果特殊需要,需要省略这些行:
1 [root@bogon zkero]# cat /etc/sysctl.conf 2 # Kernel sysctl configuration file for Red Hat Linux 3 # 4 # For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and 5 # sysctl.conf(5) for more details. 6 7 # Controls IP packet forwarding 8 net.ipv4.ip_forward = 0 9 10 # Controls source route verification 11 net.ipv4.conf.default.rp_filter = 1 12 13 # Do not accept source routing 14 net.ipv4.conf.default.accept_source_route = 0 15 16 # Controls the System Request debugging functionality of the kernel 17 kernel.sysrq = 0 18 19 # Controls whether core dumps will append the PID to the core filename. 20 # Useful for debugging multi-threaded applications. 21 kernel.core_uses_pid = 1 22 23 # Controls the use of TCP syncookies 24 net.ipv4.tcp_syncookies = 1 25 26 # Disable netfilter on bridges. 27 net.bridge.bridge-nf-call-ip6tables = 0 28 net.bridge.bridge-nf-call-iptables = 0 29 net.bridge.bridge-nf-call-arptables = 0 30 31 # Controls the default maxmimum size of a mesage queue 32 kernel.msgmnb = 65536 33 34 # Controls the maximum size of a message, in bytes 35 kernel.msgmax = 65536 36 37 # Controls the maximum shared segment size, in bytes 38 kernel.shmmax = 68719476736 39 40 # Controls the maximum number of shared memory segments, in pages 41 kernel.shmall = 4294967296 42 [root@bogon zkero]# grep -v ‘^$‘ /etc/sysc 43 sysconfig/ sysctl.conf 44 [root@bogon zkero]# grep -v ‘^$‘ /etc/sysctl.conf | grep -v ‘^#‘ 45 net.ipv4.ip_forward = 0 46 net.ipv4.conf.default.rp_filter = 1 47 net.ipv4.conf.default.accept_source_route = 0 48 kernel.sysrq = 0 49 kernel.core_uses_pid = 1 50 net.ipv4.tcp_syncookies = 1 51 net.bridge.bridge-nf-call-ip6tables = 0 52 net.bridge.bridge-nf-call-iptables = 0 53 net.bridge.bridge-nf-call-arptables = 0 54 kernel.msgmnb = 65536 55 kernel.msgmax = 65536 56 kernel.shmmax = 68719476736 57 kernel.shmall = 4294967296
标签:
原文地址:http://www.cnblogs.com/supker/p/4592779.html