Prompt
Learn how to use command line file editors.
Tutorial Video
Walk-Through
Video tutorial: Cyber Skyline NCL Summer Live - Linux Command Line - Sep 14, 2021
This challenge will give you experience running basic Linux commands. To solve these challenges, you will be using a Linux Command Line Interface (aka terminal or shell).
Background:
Editing files in the Command Line Interface (CLI) requires a text-based editor, as graphical tools like Microsoft Word, Textedit, or Notepad aren't available. Common CLI editors include nano, vim, and Emacs. Nano is the simplest, while Vim and Emacs offer more advanced features but come with a steeper learning curve. This guide focuses on nano and Vim.
Guide:
- Nano
To open nano, simply type nano
into the terminal. File names can also be included as the second argument to the command. For example, nano example.txt
will create a file named “example.txt” and will launch the application.
When launched, a list of commands is given at the bottom of the screen. Each command is preceded by a caret character ( ^ ) - this represents the “CTRL” or control key on the keyboard. The caret is used as a shorthand for the CTRL key.
Once in nano, type as you normally would in a graphical text editor. However, the mouse can not be used to change the position of the cursor in the document. Use the arrow keys to move your position within the document. A text cursor will highlight your position in the file.
When you are ready to save and exit, press the CTRL + X characters to trigger the exit process. You will be prompted to save the buffer (buffer is referring to the data) and you can press the “Y” key to save or the “N” key to discard your edits.
- Vim
Nano can often be too simple for certain tasks, which may be reason to use Vim. Start Vim by using the vim
command and optionally providing a filename: vim example.txt
There are various modes in Vim. The default normal mode in Vim functions as read-only. Press i
to enter insert mode (indicated by “INSERT” at the bottom left) where standard typing and deletions are enabled. Press Esc
to exit insert mode.
Visual mode enables copying and pasting. Press v
in normal mode to begin selecting text from the cursor. Use arrow keys to expand the selection, then press y
to “yank” it. Paste the copied text using the p
character key, which will paste the text immediately after your cursor.
To save changes after editing, ensure you're in normal mode, then enter command mode with a colon. If editing is complete, type wq
to write and quit, then press Enter. Vim displays a warning when quitting with unsaved changes. To exit without saving, use :q!
.
Vim Command | Purpose |
:q | Quit (only if there are no unsaved edits) |
:w | Save the file |
:wq | Save the file and quit |
:q! | Quit without saving |
Vim relies on keyboard commands to perform editing tasks due to the lack of on-screen buttons. Only basic features are covered here. Commands like dd
, which deletes lines, or shortcuts <SHIFT> + G
, which jumps the cursor to the end of a file, become familiar with practice.
- Renaming, Copying and Deleting Files
After creating a file with nano or Vim, it can be renamed, copied, or deleted as needed.
Rename a File: mv
Use the mv
(move) command to rename a file. Provide the original filename as the first argument and the new name as the second.
For example, mv example.txt newname.txt
renames the file in the same directory. Include a different path in the second argument to move the file to another location. Below, the file “example.txt” was renamed to newname.txt, and then was moved to the “/” directory using mv newname.txt /newname.txt
.
Copy a File: cp
Use the cp
(copy) command to duplicate a file. Specify the original filename first and the name of the copy second. For example, cp example.txt copy.txt
creates a duplicate named “copy.txt” in the same directory.
Remove a File: rm
Use the rm
(remove) command to delete a file. Specify the filename as the first argument as follows: rm example.txt
. This action is permanent and bypasses recovery options like the Recycle Bin. Restoring deleted files typically requires forensic tools.
Tools to learn more about text editors:
Questions
1. What key should you press in addition to the CTRL key to trigger the combination to exit nano?
2. What vim mode allows you to write new characters in the file?
3. What keyboard combination will save and quit the file with vim?
4. What keyboard combination will delete an entire line in vim?
5. What command would you use to rename a file?
©️ 2025 Cyber Skyline. All Rights Reserved. Unauthorized reproduction or distribution of this copyrighted work is illegal.