How do I open a large file in a terminal (using vim causes terminal to hang)? [duplicate]

When dealing with large files, it's better to minimize the amount of information you're going to deal with, and there are tools for that. One tool that has been mentioned is grep to search for specific lines that you need. Another two tools that I'd recommend using are tail and head that can display specific number of lines or bytes from top of the file ( head ) or from the end ( tail ). This is useful if you only need to read those specific parts of the file, but nothing in between.

Alternative way is to use split command. It can break down a file based on number of bytes or lines. For example,

$ mkdir SPLIT

$ cd SPLIT/                                                                                                       

$ split -l 5  /etc/passwd

$ ls
xaa  xab  xac  xad  xae  xaf  xag  xah  xai  xaj

Now, my /etc/password is broken down into smaller files, 5 lines each, which you can open with vim or other text editor


Use the command less. less uses a more efficient way of reading a file into memory. There are 2 equivalent commands: more and most (that last one you need to install). Those put the single page into memory.

But your BEST option for searching would be to use grep. Example:

grep {searchstring} {file}

And have a look at logrotate so you span that log over multiple files.

And split can split your current file into equal parts so you have an easier life looking at that log.


It depends on what your goal is.

If you want to scroll through the entire logfile, you can use the less or more commands to get a page-by-page view of the file at hand.

Otherwise, if you know where in the file you're looking for, you can use the head or tail commands to grab a section/excerpt of the file. See man head and man tail for more information as to how to search for exact parts.

If you're looking for a specific string/entry, you can use grep to search the file for your string. You can either use cat file | grep something or grep something file depending on what you want to do.

Alternatively, if you want to do some more advanced things, you could look at using sed or awk for more advanced operations, if need be.