cd 的用法ide
- cd 切換到~目錄
- cd . 切換到當前目錄
- cd .. 切換到上級目錄‘
- cd - 切換到上次所在的目錄
- cd / 切換到根目錄
- cd /data 切換到/data目錄下
pwd 用法blog
- [root@oldboyboy data]# pwd
/data
[root@oldboyboy data]#
grep 的用法
參數 : -v -E -o -n -A -B -C -i -w -cit
- grep -n 顯示文件內容的行號

- grep -v 排除文件某些字符
- grep -E 連續匹配多個字符

- grep -o 只輸出匹配的字符

- grep -A 2 1 o.txt 匹配輸出第 3 行後面的 2 行,二、3行
[root@oldboyboy tmp]# grep -A 2 1 o.txt
1
2
3
- grep -B 2 3 o.txt 匹配輸出第 3 行前面的 2 行,一、2行
[root@oldboyboy tmp]# grep -B 2 3 o.txt
1
2
3
- grep -C 2 3 o.txt 匹配輸出第 3 行先後的各 2 行,一、2和四、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.txtoldboyBBB12hh12hh1212[root@oldboyboy tmp]# grep -c '12' o.txt 4[root@oldboyboy tmp]#