Chinaunix

标题: linux下vi命令打开最大文件限制 [打印本页]

作者: dongh    时间: 2014-05-29 16:25
标题: linux下vi命令打开最大文件限制
各位大虾,谁能帮忙解决个问题啊。
我的机器内存只有4G,有时候用 vi 打开文件的时候没关注这个文件由多大就直接vi了,然后如果vi到一个20G的文件那就把内存和swap给撑爆了,然后机器就挂了。
有什么办法能让vi限制打开文件的最大值,比如说我是4G内存,我最大只允许VI打开2G的文件,超过2G就不让打开了,这样起码能保证机器不会挂。
作者: q1208c    时间: 2014-05-29 19:16
虽然可以自己把 vi 改成 alias, 然后在 执行真正的vi之前先检查文件的大小. 但这样做其实没什么意义.

实际中, 就算你有 2G 内存, 我也不相信谁会手工去编辑超过1G的文本文件.
所以, 这根本就是习惯问题.

就好象马路上要求我们靠右走, 我们总不能在路边上都装上单向门吧.
作者: Shell_HAT    时间: 2014-05-29 22:54
好像没有什么好方法可以手工限制。

32位的系统里面,最大可以打开2GB的文件。某些发行版里面的vi也有限制:
  1. vi places the following limits on files being edited.

  2. Maximum Line Length
  3. LINE_MAX characters (defined in <limits.h>), including 2-3 bytes for
  4. overhead. Thus, if the value specified for LINE_MAX is 2048, a line
  5. length up to 2044 characters should cause no problem.

  6. If you load a file that contain lines longer than the specified limit,
  7. the lines are truncated to the stated maximum length. Saving the file
  8. will write the truncated version over the original file, thus
  9. overwriting the original lines completely.

  10. Attempting to create lines longer than the allowable maximum for the
  11. editor produces a line too long error message.

  12. Maximum File Size
  13. The maximum file length of 234,239 lines is silently enforced.
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2