What is Nano?

What is Nano?

Chapter Zero: The Difficult Beginning – How to Open Your “Command Line”

The “command line” or “terminal” is the gateway to the world of experts. It is a program without a graphical interface, where you command the computer by entering text commands. Nano lives here. The way to open it varies across different operating systems.

Scenario One: If you are using Windows (Recommended Method)

Modern Windows development strongly recommends using WSL (Windows Subsystem for Linux). It allows you to seamlessly run a complete Linux system within Windows.

  1. Install WSL:

  • Open your “Microsoft Store”.

  • Search for “Ubuntu” (or any other Linux distribution you prefer; Ubuntu is recommended for beginners).

  • Click “Get” or “Install”.

  • Once installed, open your newly installed “Ubuntu” application. The first time you start it, you will be prompted to set a username and password. This password is important; nothing will be displayed on the screen as you type, just press enter when done.

  • Open the Terminal:

    When opened, the black window with a blinking cursor is our “terminal”.

    • Method A: Click the “Start” menu and find and open the “Ubuntu” application you just installed.

    • Method B (More Professional): Go to the Microsoft Store, search for and install “Windows Terminal”. After installation, open it, and it will automatically detect your installed Ubuntu, allowing you to select it from the dropdown menu. From now on, you can rely on this “Windows Terminal”.

    Scenario Two: If you are using macOS

    The terminal in macOS is built-in and very user-friendly.

    1. Method A (Fastest):

    • Press the Command (⌘) + Space keys to bring up Spotlight Search.

    • Type Terminal or the Chinese 终端 in the search box.

    • When you see “Terminal.app”, press enter.

  • Method B (Regular):

    When opened, the window you see is your terminal.

    • Click the “Launchpad” (the rocket icon) at the bottom of the screen.

    • Find a folder named “Other” or “Utilities” inside.

    • “Terminal.app” is located there.

    Scenario Three: If you are using Linux (like Ubuntu Desktop)

    Then you have it even easier.

    1. Method A: Press Ctrl + Alt + T, and the terminal window will pop up immediately. This is the fastest shortcut.

    2. Method B: Click the “Activities” or application menu in the upper left corner of the screen, type “Terminal” or “终端” in the search box, and click the icon to open it.

    Now, regardless of the system you are using, you should have a terminal window in front of you. We are officially entering the world of Nano!

    Chapter One: What is Nano? Why Learn It?

    In simple terms, nano is a text editor that runs in the command line.

    Imagine you are on a computer with only a black background and white text (like a server), with no graphical interface, no mouse, just a blinking cursor. What if you want to modify a configuration file or write a piece of code?

    nano is your savior. It allows you to easily create, open, edit, and save text files in such an environment. It is like a “Notepad” or “TextEdit” in the command line.

    Why Learn Nano?

    • User-Friendly for Beginners: All common operation shortcuts are displayed at the bottom of the screen, so you don’t have to memorize them! Just take a glance if you forget.

    • Widely Available: Almost all Linux systems (like Ubuntu, CentOS) and macOS come with nano pre-installed. You can use it anytime, anywhere.

    • Powerful Enough: For daily tasks like modifying configuration files or writing small scripts, nano has more than enough functionality.

    • Essential for Remote Work: When you connect to a server via SSH, nano is the simplest and most direct way to modify files.

    Chapter Two: Hands-On Practice! A Step-by-Step Guide to Using Nano (Enhanced Details)

    2.1 Basics: Opening/Creating Files

    The usage format of nano is: nano [filename]

    • Create a New File:

    • Open an Existing File:

    2.2 Core Operations (Must Learn!)

    Once you enter the nano interface, remember that the ^ symbol at the bottom menu represents the Ctrl key on the keyboard.

    • Input Text: Type directly using the keyboard.

    • Move Cursor: Use the up, down, left, and right arrow keys on the keyboard.

    • Save File (^O): Press Ctrl + O. The bottom will prompt for the filename; just press Enter to confirm.

    • Exit Nano (^X): Press Ctrl + X.

      • If the file has been modified but not saved, nano will ask you Save modified buffer? (Do you want to save the changes?).

      • Press Y (Yes) to save and exit, or press N (No) to discard changes and exit.

    2.3 Common Editing Functions (Double Your Efficiency)

    • Search (^W): Press Ctrl + W, enter the keyword, and press enter to search.

    • Cut Entire Line (^K): Move the cursor to a line, press Ctrl + K to cut that line.

    • Paste (^U): Press Ctrl + U to paste the previously cut content. (The combination of ^K and ^U is a powerful tool for moving lines).

    • Undo and Redo:

      • Undo: Alt + U (On Mac, it may be Esc + U)

      • Redo: Alt + E (On Mac, it may be Esc + E)

    • Copy/Paste Text Blocks (instead of just whole lines)

      • Move the cursor to the beginning of the text block you want to select.

      • Press Alt + A (in the default terminal on Mac, it may be Esc + A) to enter selection mode.

      • Use the arrow keys to move the cursor and select the area.

      • Once selected, press Alt + 6 to copy the selected text.

      • Move the cursor to the target location and press ^U to paste.

    • Jump to a Specific Line (Ctrl + _):

      • Press Ctrl + _ (which is also Ctrl + Shift + –).

      • Enter the line number at the bottom and press enter; the cursor will jump there.

    Chapter Three: Where is Nano Used?

    Scenario One: [Webmaster’s Daily] Modifying Server Configuration Files

    Background Story:

    You run a personal blog hosted on a remote Linux server. Recently, you noticed that the images on your blog load slowly. After some searching, you found that you can optimize website performance by modifying a configuration file for the Nginx web server to enable a feature called gzip compression. Now, you need to log into the server to modify that file.

    Action Steps:

    1. Log into the server: Connect to your server via SSH from your local terminal.

    2. Find and open the configuration file with Nano: Configuration files usually require administrative privileges to modify, so we will use the sudo command.

    • sudo: Superuser do, meaning “do something as a super administrator”.

  • Edit the file: nano opens this file.

    • Press Ctrl + W (search), enter gzip, and then press enter.

    • The cursor will jump to the line containing gzip, and you may see something like #gzip on;.

    • # represents a comment in many configuration files, meaning that line is inactive.

    • Your task: Move the cursor to the #, press Delete or Backspace to remove it. After modification, that line becomes gzip on;.

  • Save and Exit:

    • Press Ctrl + O, then enter to confirm.

    • Press Ctrl + X to exit nano.

  • Make the configuration effective: After returning to the terminal, you need to restart the Nginx service to load the new configuration.

  • Result: Congratulations! You have just completed a professional server configuration optimization. Through nano, you quickly located, modified, and saved critical configurations in seconds, making your website load faster. This is the core value of nano in system administration: precise, quick modification of text files.

    Scenario Two: [Programmer’s Late Night] Writing and Debugging Automation Scripts

    Background Story:

    You are a data analyst who needs to download yesterday’s log files from a website and extract them every day. This repetitive task is quite annoying. You decide to write a Shell script to automate this task.

    Action Steps:

    1. Create a script file: In your project folder, use nano to create a new script file.

    2. Write the script content: In the nano editing interface, enter the following content:

    • #!/bin/bash: This is called “Shebang”, which tells the system to use bash to execute this script.

  • Save and exit: As usual, Ctrl + O, enter, Ctrl + X.

  • Grant execution permission to the script: The newly created script file is not executable by default. You need to give it “execute” permission.

    • chmod: Change mode, a command to change file permissions.

    • +x: Add (add) executable (executable) permission.

  • Run the script: Now you can run this script.

  • Result: You quickly wrote a powerful automation tool using nano, freeing yourself from repetitive tasks. nano played the role of turning ideas into reality and rapid prototyping.

    Leave a Comment