bash unix 中查看大文件的最佳工具
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1577347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best tool in unix for viewing large files
提问by Vijay
I am a novice in unix.
I am facing a problem in viewing big log files in unix using vi.
Could you please suggest the best tool for fast viewing of big files on unix?
Additionally, could you to post your own ways of viewing the big files on unix?
我是 unix 的新手。我在使用vi. 您能否建议在unix上快速查看大文件的最佳工具?另外,您能否发布自己在unix上查看大文件的方式?
回答by
lessdoesn't need to keep the whole file in memory so it is good for viewing giant files. But for log files, the line wrapping is a nuisance.
less不需要将整个文件保存在内存中,因此非常适合查看大文件。但是对于日志文件,换行很麻烦。
回答by mouviciel
It depends on what you are looking for in this big log file.
这取决于您在这个大日志文件中寻找什么。
- If you just want to be impressed by its size,
catis enough (you can also roughly locate some unexpected visual patterns). - If you just want to take a look at it, you can use
moreorless. - If you want to monitor it while it is growing, you may be interested by
tail -f. - If you are looking for specific patterns, take a look at
grep. - If you want to extract some useful information from your big data,
perlorpythonare your friends.
- 如果你只是想被它的大小所震撼,
cat就足够了(你也可以粗略定位一些意想不到的视觉图案)。 - 如果你只是想看看它,你可以使用
more或less。 - 如果您想在它成长的同时对其进行监控,您可能会对
tail -f. - 如果您正在寻找特定模式,请查看
grep。 - 如果你想从你的大数据中提取一些有用的信息,
perl或者python是你的朋友。
回答by sleske
Actually vi(at least vim) is very performant on large files. I regularly use it to edit files in the dozens of MB range without problems.
实际上vi(至少vim)在大文件上非常高效。我经常使用它来编辑几十 MB 范围内的文件而不会出现问题。
You just need to be aware that a few operations will be slow on large files: big visual selects, global searching, and syntax highlighting. For large files, always turn off syntax highlighting (if you have it on by default): :syn off . Then you should be fine.
您只需要注意一些操作在大文件上会很慢:大视觉选择、全局搜索和语法突出显示。对于大文件,总是关闭语法高亮(如果你默认开启): :syn off 。那你应该没问题。
回答by dalloliogm
Use lessas they have already told you, or mostwhich is an extended version of lesswith more options and cool stuff.
使用less,因为他们已经告诉过你,或者most这是一个扩展版本less有更多的选择和酷的东西。
It is usually included in the repository of any linux distro.
它通常包含在任何 linux 发行版的存储库中。
回答by Sachin Chourasiya
less and tail are the most efficient for viewing long files. less displayes a portion of file at a time and you need to scroll it in up direction whereas tail facilitates you to view the last n number of lines.
less 和 tail 查看长文件最有效。less 一次显示文件的一部分,您需要向上滚动它,而 tail 便于您查看最后 n 行。

