article/Linux下打开超大文件方法.md
2022-08-28 09:57:48 +08:00

32 lines
904 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Linux下打开超大文件方法
在Linux下用VIM打开大小几个G、甚至几十个G的文件时是非常慢的。
这时,我们可以利用下面的方法分割文件,然后再打开。
1 查看文件的前多少行
head -10000 /var/lib/mysql/slowquery.log > temp.log
上面命令的意思是把slowquery.log文件前10000行的数据写入到temp.log文件中。
2 查看文件的后多少行
tail -10000 /var/lib/mysql/slowquery.log > temp.log
上面命令的意思是把slowquery.log文件后10000行的数据写入到temp.log文件中。
3 查看文件的几行到几行
sed -n '10,10000p' /var/lib/mysql/slowquery.log > temp.log
上面命令的意思是把slowquery.log文件第10到10000行的数据写入到temp.log文件中。
4 根据查询条件导出
cat catalina.log | grep '2017-09-06 15:15:42' > test.log
5 实时监控文件输出
tail -f catalina.out