How do I open a text file in my terminal?

For short files:

cat <path/your_file>

directly shows a text file in the terminal.

For longer files:

less <path/your_file>

lets you scroll and search (/ text to search Enter) in the file; press q to exit.

e.g.

cat /home/john/RESULTS.txt
less /home/john/RESULTS.txt

Another alternative is vim.

vim RESULTS.txt

Once you opened a file with vim you can insert text by typing i, for instance. If you want to save your file use :w (write) or :q (quit) or :wq (for write and quit) or :q! (quit and do not save). Sometimes you need to hit the ESC key to be able to type the commands.

Vim requires some learning, but is widely used and it is very versatile.

Check the community help wiki: https://help.ubuntu.com/community/VimHowto

Vim is an advanced text editor that provides the power of the de-facto Unix editor 'Vi' with a more complete feature set. Vim is often called a "programmer's editor," and is so useful for programming that many consider it an entire IDE. It's not just for programmers, though. Vim is perfect for all kinds of text editing, from composing email to editing configuration files.


all those are best ways and there is one more way to do this & that’s with head command.

head -n -1 filename.txt

and

head -n -0 filename.txt

both will give you the same input.

Head command Explanation:

Generally head command used to print the starting lines of the any text file.we can view the text file with

head filename.txt

That will prints the 1st 10 lines of the above text file.

If you want to specific on the number of lines which are to be view then you can use head as

head -n 20 filename.txt

Then in the above text file first 20 lines will be viewed.

If you want to view whole file data with head means then then we can get it by

head -n -0 filename.txt

Hope that above explanation will give you some idea on usage of head.