查看行數(shù)
cat xxx.log | wc -l
# wc 命令 world count cat 命令 Concatenation
查看前10行 后10行 實(shí)時打印
head -n 10 xxx.log # 打印 xxx.log 的前 10 行
tail -n 10 xxx.log # 打印 xxx.log 的最后 10 行
tail -f xxx.log
更多
sort xxx.log # 按行排序
uniq -d xxx.log # 報告或忽略重復(fù)的行蔚晨,用選項(xiàng) -d 打印重復(fù)的行
cut -d ',' -f 1 xxx.log # 打印每行中 ',' 之前內(nèi)容
sed -i 's/okay/great/g' xxx.log # 文件所有 'okay' 替換為 'great', (兼容正則表達(dá)式)
grep "^foo.*bar$" xxx.log # 匹配正則的行打印到標(biāo)準(zhǔn)輸出亭姥,這里打印以 "foo" 開頭, "bar" 結(jié)尾的行
grep -c "^foo.*bar$" xxx.log # 使用選項(xiàng) "-c" 統(tǒng)計行數(shù)
fgrep "bar" xxx.log # 如果只是要按字面形式搜索字符串而不是按正則表達(dá)式,使用 fgrep (或 grep -F)
霧霾天 等風(fēng)來