1.查看文件
cat somefile 一次性将文件内容全部输出(控制台)
more somefile 可以翻页查看, 下翻一页(空格) 上翻一页(b) 退出(q)
less somefile 可以翻页查看,下翻一页(空格) 上翻一页(b),上翻一行(↑) 下翻一行(↓)
head somefile 查看文件头部
tail somefile 查看文件尾部
tail -n 10 -f -s 1 ./log.log 没1秒展示log.log文件最后10行
3.grep pattern file
3.1 grep “被查找的字符串” 文件名
3.2 grep –e “正则表达式” 文件名
grep test test*
#查找前缀有“test”的文件包含“test”字符串的文件
testfile1:This a Linux testfile! #列出testfile1 文件中包含test字符的行
testfile_2:This is a linux testfile! #列出testfile_2 文件中包含test字符的行
testfile_2:Linux test #列出testfile_2 文件中包含test字符的行
2.重定向
>
覆盖
>>
追加
sh test.sh 1>log 2>log # 标准输出和标准错误都会各自打开log
sh test.sh 1>log 2>&1 # 标准输出打开log,而标准错误,定向到标准输出.这样只打开了一次log
sh test.sh 1>/dev/null 2>&1