【文本文件操作命令】
cat 查看文件內容
more 逐屏查看文件內容
less 逐行查看文件內容
head 顯示文件開頭部分內容
tail 顯示文件結尾部分內容
tail –f 20 /var/log/messages -f可以一直追蹤這個文件內容,一般是日志文件,20表示顯示的行數。運維工作中常用重要命令。
Cut –d: -f1 /etc/passwd 以:為分隔符 截取每行第一段字符
sort 排序
如:du |sort –n–r -n是以數字排序,-r是反向排序
-t:以冒號為分隔符
+2以第二列開始排
wc 統計文件下有多少行 多少字符
[root@localhostddd]# wc /etc/passwd
36 541637 /etc/passwd
如上:36行 54個單詞1637個字符
參數:
–l 行
–w 單詞
-c 字符
unip 將相鄰的相同行的去掉
如:
[root@localhostddd]# cut -d: -f7 /etc/passwd |uniq
/bin/bash
/sbin/nologin
/bin/sync
/sbin/shutdown
/sbin/halt
/sbin/nologin
/sbin/nologin
/bin/bash
diff 文件A 文件B 對比A和B的區別
【正則表達式】
echo *與echo “*”的區別
[root@localhost~]# echo *
aaaall.sql anaconda-ks.cfg bastest case Desktop install.log install.log.syslogxunhuan
[root@localhost~]# echo"*"
*
echo* 中bash將*理解為任意位置的任意字符
echo“*”中雙引號的作用是將內容注釋為字符串
. 任意的一個字符
* 任意多的任意字符
\ 脫意符
^ 以……開頭
$ 以……結尾
\< \> 以……開頭以……結尾
a\{18\} a重復18次
為配置文件瘦身
#grep '.\{10\}' /usr/share/dict/words
.重啟10次的(字符為10)的單詞
#grep '.\{10,\}' /usr/share/dict/words
在此文件中找出.重復10次以上的(字符大於10)的單詞
grep -v ‘^#’ /etc/httpd.conf | grep –v ‘^$’
找出除了以#開頭的,並除去以剛開頭就結尾的(空行)的內容
[abc]表示當前一個位置a、b或c
#grep ‘^[abc]’ /etc/passwd 以a或b或c開頭的
#grep '^[^1-9]' /etc/passwd 不是以1-9開頭的