0

I'm using ubuntu 20.04 .

Today I reinstalled it , and then i was trying to execute this command via terminal

sudo nano /etc/fstab

While I execute it, it opens a text file and it was supposed to open the text editor app for editing...but it's rather opening the text file in the terminal.

Now I want to open that text file via Text Editor. So, How can I do that!

3 Answers3

3

The system did what you asked. Opening the file in nano, which is a small editor that can run in the terminal. It will also run in a text console, which is very useful in case the graphical environment is broken.

The command for the graphical editor in Ubuntu is gedit. However, you cannot just change nano in your command. That would start the graphical editor with elevated permissions, i.e., as root. In some cases, running a graphical program with elevated permissions (as root) can affect the file permissions in your home, and may cause problems. Also for reasons of security, running a graphical application as root is discouraged and is being deprecated. Therefore, never use the sudo command to run graphical applications. Only use sudo for terminal commands.

The currently supported way of editing system files with a graphical editor is by using the admin:// URI. Thus, open your system file /etc/fstab with the following command to edit it with root privileges in a safe way:

gedit admin:///etc/fstab

A graphical dialog appears where you should submit your user password. The very first time in a session, you you are asked two times in a row.

Through this mechanism, you are editing a temporary copy of the system file as a regular user. Once you hit save, the system file is being updated.

See some alternative methods to edit files with GUI editors in the link.

vanadium
  • 88,010
  • Thanks.. But unfortunately I did sudo gedit /etc/fstab before seeing your comment.... I restarted my system and still it feels like okay.....So what can I do now to save my PC for a future crash or something like that????

    And one more thing, yesterday I had ubuntu installed, then after following this (I think it was the reason) sudo gedit /etc/fstab my machine stuck in the bootscreen. Then I reinstalled ubuntu :(

    – Mostakim Jan 29 '21 at 16:09
  • That is why I strongly advise not to run gedit this way. – vanadium Jan 29 '21 at 16:18
1

nano is a command-line text editor, doesn't have a GUI interface. So nano file opens the "file" in the nano editor inside your terminal. Now, it's important to note the following:

Graphical applications often store settings and other user-specific data in configuration files written inside the user's home folder. The main mechanism applications use to determine what they should use as the user's home folder is the HOME environment variable. (You can inspect it yourself with echo $HOME).

Suppose you're running gedit (a graphical text editor) as root. If you run sudo gedit, HOME will continue to point toward your home directory, even though the program is running as root. Consequently, gedit will write configuration files as root into your home directory. This will sometimes result in the configuration files being owned by root and thus inaccessible to you (when you later run the program as yourself and not as root). This mainly happens when the application has to create a new configuration file. Newly created files, by default, are owned by the user who creates them (who in this case is root, not you).


If you want to use sudo directly to run a graphical application like gedit, you can run:

sudo -H gedit

The -H flag makes sudo set HOME to point to root's home folder (which is /root).


When editing files with sudo then, it's preferable to use a command line editor like nano or vi, otherwise use sudo -H .... But, as stressed in @vanadium's answer:

Also for reasons of security, running a graphical application as root is discouraged and is being deprecated. Therefore, never use the sudo command to run graphical applications. Only use sudo for terminal commands.

0

As the other answers stated, nano is a text editor that exists in the terminal.

Use the arrow keys and the Pg UP and Pg Down keys to move your text cursor.

Use CTRL+SHIFT+c to copy highlighted text.

Use CTRL+SHIFT+v to paste text at the location of the text cursor.

You can also right-click and then select copy or paste from the drop-down menu as you normally would.

Use CTRL+o and then press ENTER to save changes to your file.

Use CTRL+x to exit nano.

To search for text in a file, use CTRL+w and then type in a search query and then press ENTER. To repeat the last search, press CTRL+w and then press ENTER to find the next instance.

Also, you can use Backspace and Delete keys to delete single characters at a time and you can use CTRL+k to delete an entire line of text but be careful if you are using line wrapping and if you are not familiar with new lines which are sometimes considered paragraphs, then don't use CTRL+k so that you don't delete something on accident.

You can find more information here.

mchid
  • 43,546
  • 8
  • 97
  • 150