view - Linux Command - Unix Command

Businessman working on laptop in startup office
Thomas Barwick / Getty Images

Most Linux distributions support a shell command called view. This command is a shortcut to invoking the Vim text editor in read-only mode. It's functionally the same as executing:

$vim -R

Viewing Files in Linux

Although you can certainly read a file (provided it's not a binary file) with Vim, as invoked by view, other common Linux shell commands also present some or all of a text file.

Use the head command to show the beginning of the file. Include a command-line switch specifying a number to show a specific number of lines from the beginning of a file. For example, to show the first five lines of magnum_opus.txt, enter:

$head -5 magnum_opus.txt

Conversely, use tail to show you the last 10 lines of a file. Run tail with the -f switch to print new lines every time a file gets written at the end of it — for example, with log files.

To view the entire contents of a file, use the less command. With this utility, use the arrow keys to go back and forth one line at a time or the space or B keys to go forward or backward by one screen. Press Q to quit the utility.