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 ?
Another alternative is
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 -n -1 filename.txt
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
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.
tail -f your_file
It will show you the last ten lines of
your_file. If a process appends something to this file, you see it on your terminal.
man tail gives you more on
It's useful to see what happens with a server when you use this command on a log file.
Press Ctrl-C to quit when you are done viewing.
There are a lot of alternatives for doing that:
Some of these programs have a lot of parameters, so check that out with --help after the command..
cat filenameprints the whole file at once
less filenamesimilar behaviour for see the file in parts
tail filenamestart reading from the tail of the file
grep text filenamefor filtering results
Hope that some of this works for you..
Lots of good options provided here already, but another option if you need to edit is emacs:
emacs -nw RESULTS.txt
might not need the
-nw, depending. You may also have to
apt-get install emacs23 or
apt-get install emacs24, or if you don't have X or don't want related X dependencies,
apt-get install emacs23-nox or
apt-get install emacs24-nox.
And in addition to
less as mentioned elsewhere, there is
more. More is less, because you see a page at a time and can't scroll via the command itself, but you can scroll with the terminal window, if you have a scrolling terminal window:
If you're in bash, you have something similar to
cat by doing:
while IFS= read a;do echo "$a";done<RESULTS.txt
use hjkl buttons to move line left/down/up/right, Esc then :q to quit
and you can PageUp/PageDown
you can also edit it here in a stright way
here you'll find more link
The shell programm
sed also has an option to print out the contents of a file.
sed -n p RESULTS.txt
sed walks through every line and prints it to the terminal. But
sed also has editing capabilities. For instance if you want to replace each comma with a dot you can write:
sed 's/,/./g' RESULTS.txt
As we seem to be listing all available alternatives of displaying any text file in the terminal, it would be quite fun to introduce
pv as technically one valid (but unusual) method, although I would normally use
cat instead for most things.
It is in the repositories and so can be installed with
sudo apt-get install pv if you don't have it already.
As the man page notes,
pv is very often used to
monitor the progress of data through a pipe...pv will copy each supplied FILE in turn to standard output (- means standard input), or if no FILEs are specified just standard input is copied. This is the same behaviour as cat(1).
pv you can literally print the file to the screen, and choose the rate (
-L) at which it appears. The example below uses a high rate (300), but if you choose a low rate such as
-L 50, it will appear as if the computer is typing out the file for you.
pv /etc/apt/sources.list -qL 300
Needless to say you can increase the rate further (
-L 8000), and the command becomes very similar to
cat, with the output appearing instantaneously.
For more information see
man pv or the Ubuntu manpages online.