How to open or view large log files in unix. vi editor complains of the file being too large to open.
If you don't need to modify the file, you can use 'more'
Read 'more' man page.
This script will pull a chunk of lines from a file into a workfile and invoke vi on the workfile.
# Usage: viewpart filename starting_line [ # ]
# Without # of lines, remainder of file is taken.
if [ $# -ne 2 -a $# -ne 3 ] ; then
???echo '\nUsage: viewpart filename starting_line [ # ]\n'
if [ ! -r $fname ] ; then
???echo "Cannot read $fname"
if [ "$lines" ] ; then
???tail +$start $fname | head -$lines > $workfile
???tail +$start $fname > $workfile
echo "\nRemove workfile $workfile ? [yn] \c"
if [ "$answer" = y ] ; then
???rm -f $workfile
???echo "\n$workfile removed\n"
???echo "\n$workfile NOT removed\n"
Many implementations of vi set the dir value to /var/tmp. This is ok if /var/tmp is a large filesystem. However, many times it is not. To change it to /tmp (or some other large filesystem), open the editor by typing:
While in the vi editor, type the command:
This will display the directory where vi is opening files. If it is pointing to a small filesystem, type the command:
:set dir=/tmp (or other large filesystem)
You can now open the file by typing:
Don't use the angle brackets around filename, it's just to highlight the syntax.
The options previously proposed are good ones and the script looks nice. This is just a "FYI" regarding temp files in vi.
If you need to set these everytime you open vi then create a .exrc file. The file will read:
Set the ownership of the file so others cannot change it. Commands can be placed in the .exrc file and will execute when vi is invoked. This is not a good thing if you are root. It can be used to do interesting things.
Do you have a UNIX Question?
Unix Home: Unix System Administration
Hints and Tips