Ade Malsasa Akbar contact
Senior author, Open Source enthusiast.
Thursday, June 28, 2018 at 21:36


Continuing Part 3, in this fourth part you will learn about text file editing with nano text editor in the Terminal. It's crucial because among the basics is you must have ability to edit system configurations. Below you will find 10 exercises and followed by a summary. Happy exercising!


Read also First Part: Navigation, Second Part: Copy & Delete , and Third Part: Combination, of the most basic command lines for Ubuntu beginners.

Expected Skills


  • You are able to edit system configuration files with and without sudo.
  • If you are able to operate nano, further you can operate more advanced command line text editor such as vim and emacs.

Command 1


Remember two things:
To exit: press Ctrl+X
To save: press Ctrl+O and Enter



Command 2


$ nano /etc/apt/sources.list

nano showing
type there: hello
Save, exit
What happened?



Command 3


$ sudo nano /etc/apt/sources.list

nano showing
Type there: hello again
Save, exit

$ cat /etc/apt/sources.list

What happened? Why?

Command 4


Delete the text hello again from Command 3 above

$ cat /etc/apt/sources.list

Command 5


sudo nano /etc/apt/sources.list

Type on the top of lines: #this is a new line of comment
Save and Exit

$ cat /etc/apt/sources.list

Command 6


$ cd ~
$ pwd
$ ls
$ nano myfile.txt

Type: this is new file
Save, exit

$ cat ~/myfile.txt

Open it with Gedit Text Editor too.

Command 7


$ cd /usr/share/doc/
$ pwd
$ ls
$ nano myfile.txt
Type: this is super file!

Save, exit
What happened? Why?

Command 8


$ cd /usr/share/doc/
$ pwd
$ ls
$ sudo nano myfile.txt
Type: this is the real super file!

Save, exit
Why it can save now?

Command 9


Plug a USB flash drive and open it with your Ubuntu file manager (Nautilus)
See the address path by pressing Ctrl+L 

$ cd /path/to/your/usb/drive
$ nano myfile.txt
Type: this is a file on the external storage
Save, exit

$ cat /path/to/your/usb/drive/myfile.txt
Open the same file with Gedit Text Editor again

Command 10


$ sudo nano /etc/resolv.conf
Type on the first line: nameserver  84.200.69.80
Save

$ while true; do dig ubuntu.com; done
See SERVER: field on the output.


Summary


  • In the Terminal, we use nano to edit text files. Use Ctrl+O to save, Ctrl+X to exit. 
  • We use sudo to edit system-owned files. Otherwise, we have no permission.
  • We can edit files both in internal storage and also external storage, as long as we know the path. Use your file manager to view it.

Notes


On the Command 10 above, that is how to change your DNS server. The DNS address there (84.200.69.80) is from public DNS.Watch Service, the fast and free DNS service. Remember that this change will be reverted back to default DNS by rebooting your Ubuntu system.

to be continued...



This article is licensed under CC BY-SA 3.0.