cd 的用法

  • cd 切换到~目录
  • cd . 切换到当前目录
  • cd .. 切换到上级目录‘
  • cd - 切换到上次所在的目录
  • cd / 切换到根目录
  • cd /data 切换到/data目录下

pwd 用法

  • [root@oldboyboy data]# pwd /data [root@oldboyboy data]#

grep 的用法 参数 : -v -E -o -n -A -B -C -i -w -c

  • grep -n 显示文件内容的行号
  • grep -v 排除文件某些字符
  • grep -E 连续匹配多个字符
  • grep -o 只输出匹配的字符
  • grep -A 2 1 o.txt 匹配输出第 3 行后面的 2 行,2、3行 [root@oldboyboy tmp]# grep -A 2 1 o.txt 1 2 3
  • grep -B 2 3 o.txt 匹配输出第 3 行前面的 2 行,1、2行 [root@oldboyboy tmp]# grep -B 2 3 o.txt 1 2 3
  • grep -C 2 3 o.txt 匹配输出第 3 行前后的各 2 行,1、2和4、5行 [root@oldboyboy tmp]# grep -C 2 3 o.txt 1 2 3 4 5 [root@oldboyboy tmp]#
  • grep -i 'b' o.txt 匹配的内容不分大小写 [root@oldboyboy tmp]# cat o.txt oldboyBBB [root@oldboyboy tmp]# grep 'b' o.txt oldboyBBB [root@oldboyboy tmp]# grep -o 'b' o.txt b [root@oldboyboy tmp]# grep -i 'b' o.txt oldboyBBB [root@oldboyboy tmp]# grep -io 'b' o.txt b B B B [root@oldboyboy tmp]#
  • grep -w '12' o.txt 只匹配12的内容 [root@oldboyboy tmp]# cat o.txt oldboyBBB 12h h12h h12 12 [root@oldboyboy tmp]# grep '12' o.txt 12h h12h h12 12 [root@oldboyboy tmp]# grep '\b12\b' o.txt 12 [root@oldboyboy tmp]# grep -w '12' o.txt 12 [root@oldboyboy tmp]#
  • grep -c '12' o.txt 计算匹配到字符的次数 [root@oldboyboy tmp]# cat o.txt oldboyBBB 12h h12h h12 12 [root@oldboyboy tmp]# grep -c '12' o.txt 4 [root@oldboyboy tmp]#