nano

text processingLinux/Unix
The nano command is one of the most frequently used commands in Linux/Unix-like operating systems. nano A simple command-line text editor

Quick Reference

Command Name:

nano

Category:

text processing

Platform:

Linux/Unix

Basic Usage:

nano [options] [arguments]

Common Use Cases

    Syntax

    nano [options] [[+line[,column]] file]...

    Options

    Option Description
    -A, --smarthome Enable smart home key
    -B, --backup Save backups of existing files
    -C directory, --backupdir=directory Directory for saving unique backup files
    -D, --boldtext Use bold text instead of reverse video
    -E, --tabstospaces Convert typed tabs to spaces
    -F, --multibuffer Enable multiple file buffers (if available)
    -G, --locking Use file locking if available
    -H, --historylog Log & read search/replace string history
    -I, --ignorercfiles Don't look at nanorc files
    -J #, --guidestripe=# Show a guide bar at specified column
    -K, --rawsequences Fix numeric keypad key confusion problem
    -L, --nonewlines Don't add newlines to the ends of files
    -M, --trimblanks Trim trailing spaces when hardwrapping
    -N, --noconvert Don't convert files from DOS/Mac format
    -O, --morespace Use more space at the bottom of the screen
    -P, --positionlog Log & read location of cursor position
    -Q "str", --quotestr="str" String to use for quoting
    -R, --restricted Restricted mode (can't read/write outside current dir)
    -S, --smooth Smooth scrolling
    -T #, --tabsize=# Set width of a tab to # columns
    -U, --quickblank Do quick status-bar blanking
    -V, --version Print version information and exit
    -W, --wordbounds Detect word boundaries more accurately
    -X "str", --wordchars="str" Characters that are part of a word
    -Y name, --syntax=name Syntax definition to use for coloring
    -Z, --zap Let Bsp and Del erase a marked region
    -a, --atblanks When soft-wrapping, do it at whitespace
    -b, --breaklonglines Automatically hard-wrap overlong lines
    -c, --constantshow Constantly show cursor position
    -d, --rebinddelete Fix Backspace/Delete confusion problem
    -e, --emptyline Keep the line below the title bar empty
    -f file, --rcfile=file Use only this file for configuring nano
    -g, --showcursor Show cursor in file browser & help text
    -h, --help Show help text and exit
    -i, --autoindent Automatically indent new lines
    -j, --jumpyscrolling Scroll by half-screen, not by line
    -k, --cutfromcursor Cut from cursor to end of line
    -l, --linenumbers Show line numbers in front of the text
    -m, --mouse Enable the use of the mouse
    -n, --noread Do not read the file (only write it)
    -o directory, --operatingdir=directory Set operating directory
    -p, --preserve Preserve XON (^Q) and XOFF (^S) keys
    -q, --quiet Silence startup warnings
    -r #, --fill=# Set hard-wrap line length to # columns
    -s program, --speller=program Use this program to check spelling
    -t, --saveonexit Save changes on exit, don't prompt
    -u, --unix Save a file by default in Unix format
    -v, --view View mode (read-only)
    -w, --nowrap Don't hard-wrap long lines
    -x, --nohelp Don't show the two help lines
    -y, --afterends Make Ctrl+Right stop at word ends
    -z, --suspend Enable suspension
    -$, --softwrap Enable soft line wrapping

    Commonly Used Keyboard Commands:

    Key Combination Action
    Ctrl+G Display help text
    Ctrl+O Save current file
    Ctrl+X Exit nano
    Ctrl+K Cut current line (or marked text)
    Ctrl+U Paste text from the cut buffer
    Ctrl+W Search for text
    Ctrl+\ Search and replace text
    Ctrl+A Move to beginning of current line
    Ctrl+E Move to end of current line
    Ctrl+Y Move to previous screen
    Ctrl+V Move to next screen
    Ctrl+_ Go to specific line number
    Alt+A Mark text starting from cursor position
    Alt+6 Copy current line (or marked text)
    Ctrl+C Show cursor position
    Ctrl+T Invoke the spell checker, if available
    Ctrl+R Insert contents of another file into current buffer
    Ctrl+J Justify the current paragraph
    Alt+J Justify the entire file

    Examples

    How to Use These Examples

    The examples below show common ways to use the nano command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    nano file.txt
    Open or create file.txt for editing.
    nano +10 file.txt
    Open file.txt and position cursor at line 10.
    # Advanced Examples Advanced
    nano +10,5 file.txt Open file.txt and position cursor at line 10, column 5. nano -B file.txt Create a backup of file.txt before editing. nano -i file.txt Enable auto-indentation while editing. nano -m file.txt Enable mouse support in the editor. nano -l file.txt Display line numbers in the editor. nano -k file.txt Toggle cut text from cursor to end of line instead of the whole line. nano -S file.txt Enable smooth scrolling in the editor. nano -w file.txt Disable line wrapping for long lines. nano -E file.txt Convert tabs to spaces while editing. nano -$ file.txt Enable soft line wrapping at specified column. nano -A file.txt Enable smart home key functionality. nano -R file.txt Open the file in read-only mode. nano -c file.txt Display cursor position information. nano -T 4 file.txt Set tab size to 4 spaces. nano -s spellcheck file.txt Enable spell checking using the 'spellcheck' program.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The 'nano' command is a simple, user-friendly text editor for Unix-like operating systems. Developed as a free replacement for the Pico text editor, nano is part of the GNU Project and has become one of the most widely used command-line text editors due to its ease of use and intuitive interface. Key features of the nano command: 1. User-Friendly Interface: nano presents a straightforward interface with command shortcuts displayed at the bottom of the screen, making it accessible to beginners without requiring memorization of complex commands. 2. On-Screen Help: The editor displays the most common keyboard shortcuts at the bottom of the screen, providing immediate reference for users. More comprehensive help is available through the Ctrl+G shortcut. 3. Syntax Highlighting: nano supports syntax highlighting for many programming and markup languages, making it easier to read and write code. This feature can be enabled through command-line options or configuration files. 4. Search and Replace: The editor includes functionality to search for text strings and optionally replace them, with support for regular expressions in more recent versions. 5. Cut, Copy, and Paste: nano provides basic text manipulation operations, allowing users to cut, copy, and paste text within the document. 6. Multiple Buffers: More recent versions of nano support editing multiple files simultaneously, with the ability to switch between buffers. 7. Auto-indentation: For programming tasks, nano can automatically indent new lines to match the indentation of the previous line, helping maintain code structure. 8. Customization: nano can be customized through the nanorc configuration file, allowing users to set preferred defaults for options, key bindings, and syntax highlighting. 9. Line Numbers: Users can enable line numbers display, which is particularly useful when editing code or when referencing specific lines. 10. Mouse Support: nano can be configured to use the mouse for positioning the cursor and selecting text, providing an alternative to keyboard-only navigation. Common use cases for nano include: - Quick editing of configuration files on servers where more complex editors might not be installed or necessary - Creating and editing simple text documents or notes in a terminal environment - Learning basic text editing in Unix-like systems, as a stepping stone before moving to more complex editors like Vim or Emacs - System administration tasks that require editing system files with minimal complexity - Programming and scripting when a lightweight editor is preferred While nano lacks some of the advanced features and extensibility of editors like Vim or Emacs, its simplicity and low learning curve make it an excellent choice for many everyday editing tasks. It strikes a balance between functionality and ease of use, making it accessible to users of all skill levels. The name 'nano' reflects its design philosophy: it's smaller and simpler than other Unix text editors, focusing on being just what users need for basic text editing without overwhelming them with features or complex commands.

    Related Commands

    These commands are frequently used alongside nano or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the nano command works in different scenarios.

    $ nano
    View All Commands