📖 Scenario: You are working on a Linux server and need to create and edit a simple text file using the nano text editor. This is a common task for writing notes, scripts, or configuration files.
🎯 Goal: Learn how to create a text file, add content, save it, and exit the nano editor using basic commands.
📋 What You'll Learn
Create a new text file named notes.txt using nano
Write the exact text: Hello, Nano! inside the file
Save the file using the correct keyboard shortcut
Exit the nano editor
Display the contents of notes.txt to confirm the text
💡 Why This Matters
🌍 Real World
Editing configuration files, writing quick notes, or creating scripts on Linux servers often requires using simple text editors like nano.
💼 Career
Many IT, DevOps, and developer roles require comfort with command-line text editors to manage files on remote servers.
Progress0 / 4 steps
1
Open a new file with nano
Type the command nano notes.txt to open the nano editor and create a new file named notes.txt.
Linux CLI
Hint
Use nano followed by the file name to open or create a file.
2
Write text inside nano
Inside the nano editor, type the exact text Hello, Nano! on the first line.
Linux CLI
Hint
Just type the text as you would in any text editor.
3
Save the file and exit nano
Press Ctrl+O to save the file, then press Enter to confirm the file name. After saving, press Ctrl+X to exit nano.
Linux CLI
Hint
Use the keyboard shortcuts shown at the bottom of nano to save and exit.
4
Display the contents of the file
Type the command cat notes.txt to display the contents of the file and confirm it contains Hello, Nano!.
Linux CLI
Hint
The cat command shows the file content in the terminal.
Practice
(1/5)
1. What is the primary purpose of the nano text editor in Linux?
easy
A. To manage system processes
B. To compile programs
C. To quickly edit text files in the terminal
D. To browse the internet
Solution
Step 1: Understand nano's role
Nano is a simple text editor used in the terminal for editing files.
Step 2: Compare options
Only To quickly edit text files in the terminal describes editing text files, which matches nano's purpose.
Final Answer:
To quickly edit text files in the terminal -> Option C
Quick Check:
nano edits text files = C [OK]
Hint: Remember nano is a text editor, not a compiler or browser [OK]
Common Mistakes:
Confusing nano with compilers or system tools
Thinking nano manages processes
Assuming nano is a web browser
2. Which keyboard shortcut saves the current file in nano?
easy
A. Ctrl+X
B. Ctrl+C
C. Ctrl+S
D. Ctrl+O
Solution
Step 1: Recall nano save command
In nano, Ctrl+O writes (saves) the file to disk.
Step 2: Identify other shortcuts
Ctrl+X exits, Ctrl+S is not standard in nano, Ctrl+C cancels commands.
Final Answer:
Ctrl+O -> Option D
Quick Check:
Save file = Ctrl+O [OK]
Hint: Save with Ctrl+O, exit with Ctrl+X [OK]
Common Mistakes:
Using Ctrl+X to save instead of exit
Assuming Ctrl+S saves in nano
Confusing Ctrl+C with save
3. What happens when you run nano myfile.txt if myfile.txt does not exist?
medium
A. nano creates a new empty file named myfile.txt for editing
B. nano shows an error and exits
C. nano opens a random file
D. nano opens the last edited file
Solution
Step 1: Understand nano file behavior
If the file does not exist, nano creates a new empty buffer with that filename.
Step 2: Check other options
It does not error out, open random or last file.
Final Answer:
nano creates a new empty file named myfile.txt for editing -> Option A
Quick Check:
Nonexistent file opens empty new file = A [OK]
Hint: nano creates new file if it doesn't exist [OK]
Common Mistakes:
Expecting an error if file is missing
Thinking nano opens a random file
Assuming nano opens last file automatically
4. You opened a file with nano but accidentally pressed Ctrl+X. What should you do to avoid losing changes?
medium
A. Press N to discard changes
B. Press Y to save changes before exit
C. Press Ctrl+C to cancel exit
D. Close the terminal immediately
Solution
Step 1: Understand nano exit prompt
Pressing Ctrl+X asks if you want to save changes: Y or N.
Step 2: Choose correct option to save
Press Y to save changes before exiting, preventing data loss.
Final Answer:
Press Y to save changes before exit -> Option B
Quick Check:
Save changes on exit = Y [OK]
Hint: Press Y to save changes when exiting nano [OK]
Common Mistakes:
Pressing N and losing changes
Trying Ctrl+C which cancels but not saves
Closing terminal without saving
5. You want to edit a configuration file quickly on a remote server using nano. Which sequence correctly opens the file, saves changes, and exits?
hard
A. nano config.txt -> Ctrl+O -> Ctrl+X
B. nano config.txt -> Ctrl+X -> N
C. nano config.txt -> Ctrl+S -> Ctrl+Q
D. nano config.txt -> Ctrl+W -> Ctrl+C
Solution
Step 1: Open file with nano
Use nano config.txt to open the file for editing.
Step 2: Save changes with Ctrl+O
Press Ctrl+O to write changes to the file.
Step 3: Exit nano with Ctrl+X
Press Ctrl+X to exit the editor safely.
Final Answer:
nano config.txt -> Ctrl+O -> Ctrl+X -> Option A
Quick Check:
Open, save, exit = Ctrl+O then Ctrl+X [OK]
Hint: Save with Ctrl+O, then exit with Ctrl+X [OK]
Common Mistakes:
Using Ctrl+X then N discards changes
Using Ctrl+S or Ctrl+Q which are not nano shortcuts
Using Ctrl+W (search) or Ctrl+C (cancel) incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.