• Start Here
    • How to Install Linux
    • Which Distro To Choose
    • 10 Best Linux Distributions of 2023
  • Distros
    • Ubuntu
  • Linux Commands
  • Virtualization
  • Open Source
Linux Start
  • Start Here
    • How to Install Linux
    • Which Distro To Choose
    • 10 Best Linux Distributions of 2023
  • Distros
    • Ubuntu
  • Linux Commands
  • Virtualization
  • Open Source
Linux Start
Home»Distros»Ubuntu»How To Edit Files In Ubuntu Terminal

How To Edit Files In Ubuntu Terminal

Anup ThapaBy Anup ThapaApril 28, 2023 Ubuntu 3 Mins Read

As you get started with Linux, you’ll inevitably have to edit config files at some point, whether it’s to change your device name, configure networking, or whatever else.

You have numerous options to choose from for this matter. There are powerful text editors like vim or emacs but they have a significant learning curve. Editors like kate or nano are better suited for beginners.

As nano comes preinstalled and is most commonly used in Ubuntu, we recommend nano for new users. We’ll explain how you can edit files with it in this article.

Opening a File with Nano

The basic syntax for opening a file to edit with nano is

nano /path/to/file

If you need root privileges to edit this file, you can simply prefix the command with sudo like so

sudo nano ~/Desktop/intro.txt

In the above example, if the intro.txt file doesn’t exist yet, the command will create a text file by that name.

Editing Files with Nano

As nano emulates the Pico text editor, two of its main selling points are simplicity and ease of use. The most commonly used shortcuts are conveniently listed at the bottom.

Control-key sequences can be entered by pressing Ctrl (e.g., Ctrl + O to save changes) or by entering Esc twice (e.g., Esc + Esc + O).

Meta-key sequences can be entered using Alt or Cmd (e.g., Alt + U to undo the last change).

The two most important shortcuts are to:

  • Write the current buffer, i.e. save the changes (Ctrl + O)
  • Close the current buffer, i.e., exit nano (Ctrl + X)

Ctrl + S works for saving too, but it’ll save the file without a confirmation prompt. And if you try to exit without writing out the changes, you’ll be prompted to save the modified buffers so that the edits you made aren’t accidentally lost.

Useful Nano Shortcuts

You could definitely get by with just the shortcuts mentioned above. But if you’re going to learn how to use nano, you might as well learn to use it efficiently. 

You can press Ctrl + G to read the full help text, but for now, here are some useful shortcuts:

  • Mark (Alt + A)
    Mark text starting from the cursor position. You can also use Shift + Arrow keys or your mouse to make a selection.
  • Copy (Alt + 6)
    Copy the current line or the selected text and store it in the cut buffer.  
  • Cut (Ctrl + K)
    Cut the current line or the selected text and store it in the cut buffer.
  • Paste (Ctrl + U)
    Paste the contents of the cut buffer at the current cursor position.
  • Undo (Alt + U)
    Undo the last operation.
  • Redo (Alt + E)
    Redo the last operation.
  • WhereIs (Ctrl + W)
    Search forward for a string or a regular expression.
  • WhereWas (Ctrl + Q)
    Search backward for a string or a regular expression.
  • Replace (Ctrl + \)
    Replace a string or a regular expression.
  • Read File (Ctrl + R)
    Read another file and insert it into the current buffer (append the contents).
  • Execute (Ctrl + T)
    Execute a function or an external command (e.g., ls).
  • Go To Line (Ctrl + /)
    Go to line and column number.
  • Count (Alt + D)
    Count the number of lines, words, and characters.
Anup Thapa
  • LinkedIn

Anup Thapa is a Linux enthusiast with an extensive background in computer hardware and networking. At LinuxStart, Anup is an integral part of our editorial team. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys experimenting with different Linux distros and reading up on things like networking and virtualization.

Leave A Reply Cancel Reply

Table of Contents
  • Opening a File with Nano
  • Editing Files with Nano
  • Useful Nano Shortcuts
Linux Start
Guides

What is the Linux Kernel?

The Linux Kernel is the core of the Linux operating system and is central to…

How To Install Linux Mint

How To Install Linux on VirtualBox

Getting Started with Linux

How to Install Linux

10 Best Linux Distros of 2023

Which Linux Distro Should You Choose? A Complete Guide to Help You Decide

© 2023 LinuxStart.com

Type above and press Enter to search. Press Esc to cancel.