10 most popular command line text editors and viewers in linux and unix

The command line interface (CLI) is a very important feature in Linux and Unix environments that you should master to get the most out of these systems. Almost all functions/features that you can perform in a desktop environment can be done using a command line. This function can be highly beneficial when you are working remotely using ssh or something similar.

One most commonly done task is to view and edit text files. There are several desktop editors that allow you to do this, most with a lot of features. We will look some of the text editors and viewers that you can use exclusively from the command line with out the need to access an X server.

cat

cat is a very simple command to display or print out the contents of the file to the standard output. It can handle files with any amount of content and is usually very responsive and fast.

bash$ cat mynotes.txt

However, the cat has very limited functionality and does not allow you see the content by page or pause the output. It works best for small files. When using it for files with large amounts of content, it tends to scroll off very fast.

head

Sometimes, you just want to see only a part of the content and not the entire file content. The head command allows you to print out just the start or beginning lines of the file.

bash$ head -n 25 mynotes.txt

You can use the command line option -n or –lines to specify how many lines of content you want to display.

tail

The tail command is a variation of the head command in that it will display the last lines of the files, rather than the beginning.

bash$ tail -n 25 mynotes.txt

The example command above will print the last 25 lines of the file named mynotes.txt.

more

more is a very simple command line utility that can be used to display text file content. It has a pager like functionality and it displays content by screenful, one page at a time.

bash$ more mynotes.txt

The above command displays the content of the file named mynotes.txt.

The more command has very limited functionality and most notably lacks the ability to navigate between the pages easily. It is quick and easy way to view file content by page. You can pipe the output of another program using more which allows you to view it more easily.

less

less is another pager utility that works very similar to the more command. It was developed as an attempt to fix the navigation deficiencies of more utility. The less command allows you to navigate the output backwards and forwards as well as line by line.

bash$ less mynotes.txt

The utlities mentioned above are all text viewers. Now we will see programs that can be used as text editors. You can invoke all of this programs by typing the command name followed by the file name you want to edit.

ed

ed is probably one of the earliest text editor developed for Unix systems. It is actually a line editor, one of the earliest form of text editors. In modern systems, it pretty much works like a text editor.

It is probably not the widely used of text editors, but is worth the mention.

pico

pico is a rudimentary text editor, originally designed to work with the pine email client. It is short for pine composer. It does not support multiple file editing and many other features found in more advanced editors.

It is however a very robust editor for quick and simple edits. It is almost guaranteed to work on any distribution (as long as it is installed) and machine configuration. It is a keyboard orientated interface with control key commands performing almost all functionality.

nano

The nano editor is an improved variation of the pico editor. It is pretty similar to pico and is keyboard oriented. It is uses the control and meta keys for most of the commands. There is also support for some pointer devices like the mouse.

nano is probably more widely used than pico. nano is one of those text editors that it is perfectly for simple and quick text edits with enough functionality. It is very resource friendly and fast.

vi or vim

The vi is one of the most popular text editor in the modern operating system. It is a very powerful screen oriented text editor which is also very simple to use, which probably contributes to its popularity.

Although, it is feature rich and supports its own language (eg. ex), it is still very easy to learn and you don’t need to know all its features and functionality to use it as a text editor.

The vi editor has gotten so popular that there are several different variations and clones of the same. The gvim, vim, elvis are all clones of vi and popular on its own right.

emacs

Emacs is a very powerful text editor that has once been the favored editor of programmers. It is extensible, customizable, self-documenting with over 2000 built-in commands and macros.

The use of macros allows one to automate almost all actions, which makes it very powerful as a text editor. It also supports almost all other features commonly found in graphical editors.