How to Find in Nano text Editor in Linux

This guide will provide a comprehensive walkthrough on how to perform searches, including case-sensitive searches, backward searches, and search-and-replace operations.

The search functionality in Nano is straightforward yet powerful, making it easier to navigate and edit text files efficiently. Here’s a quick recap:

  1. Search: Use Ctrl + W to search for a word or phrase.
  2. Find Next Match: Press Alt + W to locate subsequent occurrences.
  3. Case-Sensitive Search: Enable it with Alt + C.
  4. Search Backward: Use Ctrl + Shift + 6.
  5. Search and Replace: Use Ctrl + \ to replace text interactively.

Table of Contents
  1. How to Find in Nano Text Editor
  2. How to Perform a Case-Sensitive Search
  3. How to Search Backward in Nano
  4. How to Find and Replace Text in Nano Text Editor
  5. How to Find All Occurrences

1. How to Find in Nano

1. Open the file you want to search:

nano filename.txt

2. Press Ctrl + W to initiate a search. A prompt will appear at the bottom

find in nano

3. Type the word or phrase you want to find and press Enter.

command to search in nano text editor

4. Nano will jump to the first occurrence of the search term.

5. To find the next occurrence, press Alt + W and repeat as needed.


By default, Nano’s search is case-insensitive, but you can enable case-sensitive searching as follows:

  1. Press Ctrl + W to open the search prompt.
  2. Press Alt + C to toggle case-sensitive mode.
  3. Type the word or phrase, ensuring the case matches what you’re searching for, and press Enter.

Nano will locate matches that exactly match the specified case.


3. How to Search Backward in Nano

Sometimes, you may need to search backward from the current cursor position. Follow these steps:

  1. Open the file in Nano:
    nano filename.txt
  2. Place the cursor where you want to start searching backward.
  3. Press Ctrl + W to open the search prompt.
  4. Type the word you want to find and press Ctrl + Shift + 6 (or Esc + 6 in some setups).

Nano will search backward and jump to the first match it finds.


4. How to Find and Replace Text in Nano

Nano also supports a search-and-replace function, which allows you to replace specific words or phrases with new ones.

Steps to Find and Replace:

1. Open a file in Nano:

nano filename.txt

2. Press Ctrl + \ to start a search-and-replace operation.
3. At the prompt, type the word you want to replace and press Enter.
4. Enter the new word or phrase and press Enter.
5. Nano will prompt:

Replace this occurrence? (Y)es / (N)o / (A)ll / (^C)ancel

6. Press Y to replace the current occurrence.
7. Press N to skip.
8. Press A to replace all occurrences automatically.
9. Press Ctrl + C to cancel.


5. How to Find All Occurrences

To find all occurrences of a word in Nano, follow these steps:

  1. Press Ctrl + W to search for the word.
  2. After finding the first match, press Alt + W to jump to the next match.
  3. To move backward through the matches, press Alt + Q.
  4. Use Ctrl + \ if you want to replace any occurrences as needed.