Home Nano Editor Tips How to Search and Replace Text in Nano Editor

How to Search and Replace Text in Nano Editor

As you grow and mature your computing skills and prowess under the Linux ecosystem, you soon find yourself comfortable with the productivity status associated with the Linux command-line environment.

The fact is true, especially for users seeking to master Linux administration footprints. The nano editor is an important file editing tool for such users. It even makes more sense to use nano editor server environments where GUI is not available.

Nano text editor is not as advanced as the likes of vim editor but it qualifies as the perfect starting point before Linux users can transition to those other text editors.

This article will walk us through searching and replacing text on a file opened under the nano text editor in Linux systems.

Why Search and Replace Text?

The search and replace text functionality in nano editor is a key solution to many practical problems. For instance, consider the scenario where you are dealing with a very large document file. Maybe this document is a documentation file of an old software version release.

Given the fact that a new software version release is out, we might only need to replace some keywords on the old software documentation file for it to match the properties of the new software version release. Such an instance calls for a search and replace text expertise.

Problem Statement

For this guide to make more sense, we need a sample file with some text to successfully demonstrate the search and replace text functionality in the nano editor.

Consider the following file opened by the nano editor.

Sample Text File in Nano Editor
Sample Text File in Nano Editor

We are going to assume that we are dealing with an extremely large file that is not easily scrollable.

Search and Replace Text in Nano Editor

In reference to the above screen capture, let us assume we want to search for the text “Linux” and replace it with the text “LinuxShellTips”.

To launch the search bar, use the keyboard key combination [Ctrl]+\.

Nano Editor Search Bar
Nano Editor Search Bar

We can now key in the text we want to search and replace throughout the file:

Enter Text to Replace in Nano Editor
Enter Text to Replace in Nano Editor

Press [Enter] on your keyboard.

Replace Text in Nano Editor
Replace Text in Nano Editor

You will now be required to key in the replacement text for your previously searched text.

Enter Text to Replace in Nano Editor
Enter Text to Replace in Nano Editor

Once you hit enter on your keyboard, you will have the option of confirming the replacement of each text match found or agreeing to replace all the text that matched the search at once.

Confirm Text Replace in Nano Editor
Confirm Text Replace in Nano Editor

Once done, you will have successfully replaced the searched text.

Search and Replace Text in Nano Editor
Search and Replace Text in Nano Editor

You can now comfortably search and replace text in a nano text editor. Hope the article guide was helpful. Feel free to leave a comment or feedback.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.