查看行數
cat xxx.log | wc -l
# wc 命令 world count cat 命令 Concatenation
查看前10行 后10行 實時打印
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 # 報告或忽略重復的行,用選項 -d 打印重復的行
cut -d ',' -f 1 xxx.log # 打印每行中 ',' 之前內容
sed -i 's/okay/great/g' xxx.log # 文件所有 'okay' 替換為 'great', (兼容正則表達式)
grep "^foo.*bar$" xxx.log # 匹配正則的行打印到標準輸出,這里打印以 "foo" 開頭, "bar" 結尾的行
grep -c "^foo.*bar$" xxx.log # 使用選項 "-c" 統計行數
fgrep "bar" xxx.log # 如果只是要按字面形式搜索字符串而不是按正則表達式,使用 fgrep (或 grep -F)
霧霾天 等風來