nano Editor in Practical DevSecOps Labs: Editing Files Simply
GNU nano is a beginner-friendly terminal text editor. Unlike vi, it has no modes — you can start typing immediately. This article covers the essential nano skills for the Practical DevSecOps labs.
Table of Contents
Opening a File
nano security-report.json # opens existing file or creates new one
Once opened, the file contents are displayed and you can immediately navigate with arrow keys and edit the text.
To exit without making changes:
# Press Ctrl + X
Editing Files
nano is a modeless editor. You can start editing text as soon as you open a file.
Example workflow
- Open the file:
nano security-report.json - Use arrow keys to navigate to the desired line
- Type your changes directly
- Save:
Ctrl + O, thenEnter - Exit:
Ctrl + X
Adding content
For example, to add a new JSON property on line 2:
"Name": "SQL Injection",
The file would look like:
{
"Name": "SQL Injection",
"Vulnerabilities": "10",
"Valid": "2",
"Severity": "High",
"generated_at": "2022-05-16T17:37:50Z"
}
Essential Shortcuts
| Shortcut | Action |
|---|---|
Ctrl + O |
Save (write out) the file |
Ctrl + X |
Exit the editor |
Ctrl + K |
Cut the current line |
Ctrl + U |
Paste (uncut) the last cut text |
Ctrl + W |
Search (where is) for a string |
Ctrl + \ |
Replace a string |
| Arrow keys | Navigate the document |
Cmd + V (macOS) / Ctrl + Shift + V (Windows/GNOME) / Shift + Insert (Linux) |
Paste from clipboard |
Note: After
Ctrl + O, nano asks for the filename. PressEnterto confirm the current filename.
Common Questions
| Question | Answer |
|---|---|
| How do I exit nano? | Press Ctrl + X. If you have unsaved changes, you'll be asked to save first. |
What does Ctrl + O do? |
It writes (saves) the file. You then need to press Enter to confirm the filename. |
| Is nano better than vi? | nano is easier for beginners. vi is more powerful and available on more systems. Both are useful. |
| Can I search in nano? | Yes, press Ctrl + W and type your search term. |
| How do I select multiple lines? | Press Alt + A to set a marker, navigate, then Alt + A again to toggle selection. |
Wrap-Up
nano is the go-to editor for quick file edits in the Practical DevSecOps labs. Remember: Ctrl + O to save, Ctrl + X to exit. No modes to worry about — just open, edit, save, and close.