By using the nano text editor provided by Linux, we can easily do some simple text editing operations such as adding, deleting, modifying, etc.

Nano Version

We can take a look at the version of nano:

1
nano -V    # This is equivalent to nano --version
img

Checks the version of the nano we are currently using

Editable Mode

We can open a text editor that is editable by running the nano command directly:

1
nano
img

Running the nano command

img

Nano editor opened in editable mode

Let’s fill in the editor with the following two lines:

1
2
First Line
Second Line
img

Filling the contents

Write Content to a File

The symbol ^ (caret) corresponds to the ctrl key on our keyboard.

We can use the combination keys (Ctrl+O) to specify the name of the file that is used to hold the content:

1
Ctrl+O
img

A prompt shows up asking what the name of the file is

img

After pressing the enter key, nano saves the content to a text file named nano_file

We can use the combination keys (Ctrl+X) to exit nano program.

Let’s take a look at the contents of the file we just created through the nano editor:

1
cat nano_file
img

Outputs the content of the newly created text file nano_file

Enable Mouse Operation

Nano also provides mouse support by adding the -m parameter:

1
nano -m
img

Entering nano editor in mouse enabled mode, this will allow us to interact nano menus with mouse pointer

We can try clicking on the red box area in the screenshot shown above.

img

Now we are on the write out page

We can click the cancel option to exit to the editor page:

img

Now we are on the main page

We can click the exit option to exit the editor.

Viewable Mode

We can enter the view mode with the-v parameter provided by the nano tool, in which all of our edits on the specified file are invalid.

1
nano -v nano_file    # This is equivalent to nano --view
img

Open nano_file in viewable mode

img

Opened in viewable mode

As shown in the screenshot below, we can’t do any changes to the file inside viewable mode.

img

Typing something in the viewable mode

Edit an Existing File

We can use nano to edit an existing text file:

1
nano nano_file
img

Opening a text file to edit

img

Editing the opened nano_file

img

Add another line

img

Write out page

img

Write out the edited content to existing nano_file

img

Outputs the edited nano_file

References Nano 2.3.x Command Manual

Buy me a coffeeBuy me a coffee