How do I open a text file in my terminal?

There is a file named RESULTS.txt and I want to open this file in my terminal. (I mean I want to see the file contents be displayed in the terminal and not in some text editor)

How do I do that ?


Solution 1:

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

Solution 2:

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.