You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: How to Use Nano Text Editor Commands in Linux
14
14
---
15
15
16
16
GNU nano is a popular command line text editor used on many operating systems including Unix-based systems and BSD variants. It is a popular editor for users who may find `vi` or `emacs` commands to be non-intuitive.
17
17
18
18

19
19
20
-
## Installing Nano
20
+
## Nano Set Up and Basic Commands
21
21
22
22
Nano is included with many Linux distributions by default, but some users may need to install it through their distribution's [package management](/docs/using-linux/package-management/) tool:
23
23
@@ -31,11 +31,11 @@ CentOS/Fedora users can issue the following command to install nano:
31
31
32
32
When using nano, control characters (CTRL) are represented by a carat (`^`). For example, if you wish to cut a line of text, you would use the "CTRL" key followed by the "K" key. This sequence of commands is represented as `^K` in nano. Some commands use the "Alt" key in order to function, which is represented by the letter "M". A command represented as `M-R` in nano would be performed by pressing the "Alt" key followed by the "R" key. Please note that Mac users may need to use the "Escape" (Esc) key instead of the "Alt" key to perform these commands.
33
33
34
-
## Creating and Opening Files
34
+
## Create and Open Files
35
35
36
36
There are different ways to start nano depending on what type of file you wish to edit. Please read through the options below to determine which is best for you.
37
37
38
-
### Creating Files
38
+
### Create Files
39
39
40
40
Nano can be used to create blank files that are then opened to be edited. To create a new file, issue a command similar to the following:
41
41
@@ -45,7 +45,7 @@ In the command above, nano is used to create a file called `index.html` in the `
45
45
46
46
You do not need to provide an absolute path for the file you wish to create. If the file already exists, nano will simply open it instead of creating it. If you decide not to save the file after you edit it, no new files are created on the file system.
47
47
48
-
### Opening Text Files
48
+
### Open Text Files
49
49
50
50
To edit a basic text file (e.g. that end with `.txt`), you can use `nano /path/to/file.txt` to open or create a text file in a specific location. If you wanted to open a file located at `~/mystuff/plan.txt`, you would issue the following command:
51
51
@@ -61,21 +61,21 @@ To open a file as "read only," use the following form:
61
61
62
62
nano -v myfile
63
63
64
-
### Opening Configuration Files
64
+
### Open Configuration Files
65
65
66
66
When editing files used to configure applications or system utilities, it is important that you start nano with `-w`.
67
67
68
68
nano -w /etc/mysql/my.cnf
69
69
70
70
Opening nano in this manner will prevent it from wrapping lines that are too long to fit on your screen, which can create problems if config directives are saved across multiple lines. `nano -w` is also useful for creating new files that you do not wish to word wrap.
71
71
72
-
## Editing Files
72
+
## Edit Files
73
73
74
-
### Cutting and Pasting
74
+
### Cut and Paste Lines of Text
75
75
76
76
To cut a line of text, use `^K`. To paste it back, simply move the cursor where you want the text to be placed and use `^U`. If you would like to cut multiple lines, use a series of `^K` commands until all lines you wish to cut have been removed. When you go to paste them back with `^U`, the lines will all be pasted at once.
77
77
78
-
### Searching
78
+
### Search Text
79
79
80
80
To search for text in a document, use `^W`. When using this command, you will be presented with a number of options to assist you in your search.
81
81
@@ -94,11 +94,11 @@ If you wish to search for text by using a regular expression, you may do so by e
94
94
95
95
To go to a line number, enter `^T` at the search prompt and enter the line number that you wish to navigate to.
96
96
97
-
#### Find and Replace
97
+
#### Find and Replace Text
98
98
99
99
At the search menu, enter `^R`. You will be presented with two prompts. The first prompt will ask you to enter the text you wish to replace. Once you have done so, enter the test you wish to replace the previous text with.
100
100
101
-
### Spell Checking
101
+
### Spell Check
102
102
103
103
Nano has a built in spell checking feature that relies on the `spell` package to function. To install this package, issue the appropriate command from below:
104
104
@@ -112,15 +112,15 @@ CentOS/Fedora:
112
112
113
113
Once you have installed spell, you may use the spell checking feature by issuing `^T` while editing a file.
114
114
115
-
## Saving and Exiting
115
+
## Save and Exit
116
116
117
117
When you're done editing your file, you can save it and exit the program.
118
118
119
-
### Saving
119
+
### Save
120
120
121
121
To save your work, issue `^O` or "WriteOut". This will save the document and leave nano open for you to continue working.
122
122
123
-
### Saving with Backups
123
+
### Save with Backups
124
124
125
125
Nano will allow you to create backups of files that you are editing when you exit. These backups can be placed in a directory that you choose, otherwise these backup files are placed in the same directory as the modified file.
126
126
@@ -130,6 +130,6 @@ Using the `-B` option when starting nano will create backups of the file for you
130
130
131
131
The command listed above will create a backup copy of `index.php` in the `backups` folder in the current user's home directory.
132
132
133
-
### Exiting
133
+
### Exit
134
134
135
135
Once you're ready to exit, issue `^X` to exit nano. If you have not saved your work, you will be prompted to save the changes or cancel the exit routine.
0 commit comments