Linux Applications

How to Open a File With Nano Editor in Linux?

“GNU nano is a text editor for Unix-like computing systems or operating environments using a command line interface.

To learn more about nano, check this out:

https://www.nano-editor.org/

Today, we will explore how to use a nano editor to open files. Here, you will learn multiple ways to use nano editor to edit files. By the end of this article, you will become comfortable with using this editor. We have used Manjaro Linux 21 to demonstrate the process.”

Let’s begin!

Guide

Following are some of the ways you can open a file using Nano editor:

Method 1: Open Nano First, and Then the File

In this method, we will open the Nano editor first and then open the file by typing the file name.

To open the editor, run the nano command like this:

nano

Once the editor is open, press Ctrl + O and write the name of the file, you want to open, and then hit enter to save it.

Method 2: Open a New File Directly From Terminal

In this method, we will show you how to create and open a new file directly from the command line.

We will follow the following Syntax:

nano filename

To create and open the new file, type nano followed by the filename and then hit enter to execute the command:

 nano test-file

This will create a new file and open it like this:

Method 3: Open an Existing File From the Command Line

Now let’s see how to open an already existing file on your machine.

First, go inside the directory where the file is saved. Once you are inside the directory, run the command “nano” followed by the filename as shown below:

 nano sample.txt

As you can see, the sample.txt file is now open to be edited with nano editor.

Method 4: Open Multiple Files From Terminal

Instead of opening just one file, you can also open multiple files at a time. This can be achieved by using the following command syntax:

nano file1 file2 file3

Suppose three files already exist on your system in some directory. To open these files in parallel, go to the directory where the files are kept. Then run the nano command followed by the filenames as demonstrated below:

nano test-file1.txt test-file2.txt test-file3.txt

All three files will open.

The above window shows 1/3 of the files. To switch to test-file2.txt, press alt+.

alt+.

This is how you can switch between the three files.

Conclusion

In today’s guide, we saw in detail how we could use Nano editor using four different ways. We explored how we can create a new file using nano as well as how to open an existing file.

We hope you liked the tutorial.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.