Editing files in a terminal

Lesson 28 of 30 · Working with Linux

A terminal editor works inside the terminal window, including during a remote session. The text you see is usually held in a buffer until you save it; changing that buffer is not the same as changing the file on disk.

The earlier Neovim walkthrough covers opening, saving and leaving a file. Another option is Nano. If it is already installed, open a new file in a fresh disposable directory:

nano memo.txt

Type Review the logs. Nano’s on-screen shortcuts use ^ to mean Ctrl. Press Ctrl+O to write, check the proposed filename and press Enter to confirm; then Ctrl+X exits. Back at the shell, cat memo.txt displays the saved line. Exact prompts vary by version and situation. If you choose to exit with unsaved changes, read the prompt carefully: discarding them loses the buffer’s changes.

If writing fails, inspect the message, path and permissions rather than opening the editor with elevated privileges by habit. Removing an exposed secret from the visible file does not remove copies or history; rotate or revoke it and follow the applicable incident procedure.