Worksheet 2 - Nano commands

From Sensors in Schools
Revision as of 18:26, 18 October 2024 by EdmondLascaris (talk | contribs)
Jump to navigation Jump to search

10-command challenge exercise using nano on a Raspberry Pi

Each challenge introduces the basics of the nano editor and teaches students common tasks, helping them become comfortable with the command-line text editor.

1. Open a File in nano

Instruction: Open an existing file using nano.

Command: nano filename.txt

Challenge: Open a file called welcome.txt and add the text "Welcome to the Raspberry Pi" at the beginning.

2. Save and Exit nano

Instruction: Learn how to save a file and exit.

Command: Press CTRL + O (to save) and CTRL + X (to exit).

Challenge: After modifying welcome.txt, save the changes and exit nano.

3. Search for Text

Instruction: Use nano's search feature to find specific words or phrases.

Command: Press CTRL + W and type the word you want to find.

Challenge: Search for the word "Raspberry" in welcome.txt and confirm its position.

4. Cut and Paste Text

Instruction: Use nano to cut and paste text.

Command: Move the cursor to the start of the line and press CTRL + K (cut) and CTRL + U (paste).

Challenge: Cut the line that contains "Welcome to the Raspberry Pi" and paste it at the end of the file.


5. Copy and Paste Text

Instruction: Use the copy and paste commands in nano.

Command: Press CTRL + Shift + 6 to start selecting, then CTRL + K to copy and CTRL + U to paste.

Challenge: Copy the first two lines of the file and paste them at the end.


6. Undo and Redo Changes

Instruction: Undo and redo changes in nano.

Command: Press ALT + U to undo and ALT + E to redo.

Challenge: Undo the last action you performed, and then redo it.


7. Jump to a Specific Line

Instruction: Jump to a specific line number in the file.

Command: Press CTRL + _ (underscore), then type the line number.

Challenge: Jump to line 5 in welcome.txt.


8. Insert the Current Date and Time

Instruction: Insert the current date and time in nano.

Command: Press CTRL + T (in some configurations) or manually type the date.

Challenge: Insert today's date and time at the end of the file.


9. Open nano in Read-Only Mode

Instruction: Learn how to open a file in read-only mode.

Command: nano -v filename.txt (use -v for read-only).

Challenge: Open the welcome.txt file in read-only mode and attempt to modify it. Note what happens.

10. Enable Syntax Highlighting

Instruction: Enable syntax highlighting in nano (for Python or other languages).


Command: Modify the `~