1、head
head -n 10 test.log 查询日志文件中的头10行日志;
head -n -10 test.log 查询日志文件除了最后10行的其他所有日志;
head -n 10 test.log 查询日志文件中的头10行日志;
head -n -10 test.log 查询日志文件除了最后10行的其他所有日志;
2、sed
只查看文件的第5行到第10行
sed -n '5,10p' filename
按照时间段
sed -n '/2014-12-17 16:17:20/,/2014-12-17 16:17:36/p' test.log
3、cat
cat 是由第一行到最后一行连续显示在屏幕上
一次显示整个文件
cat filename
从键盘创建一个文件 :
cat > filename
将几个文件合并为一个文件:只能创建新文件,不能编辑已有文件.
cat file1 file2 > file
将一个日志文件的内容追加到另外一个 :
cat -n textfile1 > textfile2
清空一个日志文件:
cat : >textfile2
4、less
查看文件
less log2013.log
查看进程信息并通过less分页显示
ps -ef | less ps
查看命令历史使用记录并通过less分页显示
history | less
浏览多个文件
less log2013.log log2014.log
5、history
所有的历史记录
history //
历史记录中包含某些指令的记录
history | grep XXX //
分页查看记录
history | more //
清空所有的历史记录
history -c //