How to open a document in terminal

Open a document in command line interface (also called CLI or Terminal) you simply type the name of the program you want to use, followed by the name of the document. Of course, the name of the document is the whole path to it. If you are already in the same directory (you navigated there with cd ) than the name will be enough. You'll find out more about navigating in terminal here

Thus, to open the document example.txt in folder /home/user/Documents, type the following:

user@computer:~$ gedit /home/user/Documents/example.txt

or navigate to the Documents folder and type simply gedit example.txt:


user@computer:~$ cd /home/user/Documents
user@computer:~/Documents$ gedit example.txt

To open a document as a super user you need to use the sudo command before the name of the program (or open the terminal as root).

You can also ask the terminal to open a file with your favorite program (the same thing of clicking twice). To do this use the command xdg-open:


user@computer:~$ xdg-open Documents/exemplo.pdf

Important: if you are working in a machine without graphical interface or if you are remotely another computer, you will not be able to use gedit as a text editor. In this case you will need to use a text editor without graphical interface.

A lot (really) of tutorials in the Internet ask you to edit files with editors without graphical interfaces. These editors are, actually, incredibly good, but are also very intimidating to the new user. I suggest that until you are a little more familiar with Linux, use user friendly editors as gedit. These are some of the editors without graphical interface used out there: vi, vim, emacs, nano. When you find these editors in a tutorial, fell free to replace that command with gedit or kate, for instance, that are beginners friendly programs.

Thus:


user@computer:~$ nano exemple.txt

May be replaced by:


user@computer:~$ gedit exemple.txt

When you are comfortable with Linux start learning vim or emacs. They're spectacular tools and it is worthy to learn.

comments powered by Disqus