Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 3: Linux Basic Commands

AWS Cloud

3.10 Text editors: nano and vim

Friends, terminal editors can edit text files on a server. Practise whichever your learning system provides. Nano offers visible shortcuts. Vim uses modes to switch between typing and editing commands.

nano — easiest for beginners

After creating the disposable lesson files in the exercise below, open your own draft.

nano ./nano-draft.conf

GNU Nano typically shows shortcuts at the bottom. The caret indicates Control. In the classic bindings, Ctrl+O opens Write Out. Check the filename and press Enter to write. Ctrl+X exits, Ctrl+W starts search, Ctrl+K cuts and Ctrl+U pastes from the cut buffer. Confirm the actual shortcuts shown for your version and settings.

Vim editing modes

Vim has modes: Normal (for commands, the default), Insert (for typing) and Command-line (after :).

Keys Action
i Enter insert mode (start typing)
Esc Back to normal mode
:w Save
:q Quit (:q! quit without saving)
:wq or ZZ Write and quit. In Normal mode, ZZ writes only if the file was changed.
dd / yy / p Delete (cut) line / copy line / paste
u / Ctrl+R Undo / redo
/text then n Search forward, next match
:set number Show line numbers
gg / G Go to first / last line
:%s/old/new/gc Review and confirm each pattern replacement across the current buffer.

Stuck in vim?

For the single-file exercise, press Escape to return to Normal mode. If you want to discard the current unwritten changes, type :q! and press Enter. A previous save remains on disk.

Ravindra Bagale's Tip

A swap warning can indicate another editor or recoverable work from a previous session. Read the warning and check before changing either file. If you type :wq in Insert mode it becomes buffer text. Use Escape to reach Normal mode before issuing the write command.

Lab

Chala, create the new practice directory in the worked exercise below. Open one sample draft, change only the report limit and write the selected file. Compare it with the original using diff -u. Start from the same original for each editor, so you can see that both can save the same result.

Make one deliberate change to a text file

Mauli Dairy's report review screen shows 25 deliveries at a time. The support team wants to try 50 on a training copy because the next shift may have a larger list. The setting is written on one line in a plain text file. Asha could open the file, type a new number and leave. She still has to answer three questions for the rest of the team. Which path did she edit? Did the editor actually write her changes to that file? Did anything else change? This lesson gives you a short editing workflow that answers all three.

Plain text files store characters and line breaks in a particular encoding. They can hold notes, scripts, configuration or other simple data. A terminal text editor lets you change those characters using keyboard commands. For an application setting, one extra space, a duplicate entry or a misspelled name can change what the program reads. The format is a contract with that program. In our fictional report configuration every setting has a name, an equals sign and a value. Other file formats have other rules. Read the rules of the application or exercise before editing a real file.

We will prepare an original and two copies in a fresh private folder. We will revise one copy with GNU nano and one with Vim if the editors are available. Then we will compare the result from the shell. The intended change is one line and the original remains available as a reference. This makes it possible to distinguish learning the editor from improving the application's real configuration. The fixture has no connection to a running report service. You can choose the editor you have and read the other exercise if you are still learning only one.

Use an ordinary shell and a location in your home directory that you control. The commands for creating and comparing files use Bash and standard utilities. GNU nano and Vim are implementations, so confirm the program and visible keys in your environment. Some systems provide a different terminal editor under a familiar name. A terminal-window session inside SSH opens the remote machine's editors and files. Check the host and working directory before assuming a file you will edit is on your own computer.

Distinguish a buffer, a filename and a saved file

An editor usually reads the file contents into a buffer, a working copy it can display and change. When you type a new value into the buffer, it may be visible on the screen before the file on disk changes. The editor commonly provides a modified indicator when there are unwritten edits. A write operation saves contents to a chosen filename. Some editors can save automatically if configured that way, so check the environment where you are learning. The defaults in the examples let you explicitly choose when to write. We will confirm the disk result from the shell to keep that distinction visible.

There may also be several buffers or windows. The visible file label tells you which work the current editing commands address. Your current shell directory explains a relative path at launch. The editor may remember or change its own working directory. When a filename prompt appears before saving, check the destination again. A file called report.conf could exist in an old release and the current release. A text editor can create a new buffer for a path that does not exist yet, especially if you mistype the name. An empty screen is a reason to verify the path before typing an entire replacement.

Keep four events separate. Opening reads the file or starts a buffer for a new path. Editing changes the working text. Writing makes a persistent file change to the selected destination. Quitting closes an editor or buffer. You can write while staying in the editor. You can discard unsaved edits and leave. You can also write to another filename, which changes the destination that needs checking. Knowing the sequence helps explain why a saved change is still present after a later quit without saving. The quit choice applies to changes still in the buffer after the last successful write.

The cursor shows where a key will act. The status line and bottom prompts show which part of the editor is currently receiving input. If a shortcut brings up a search box, the text you type belongs to that search until you confirm it. If a shortcut brings up a filename prompt, inspect the file before accepting it. An error displayed on the status line can explain a refused write. Read that message and the current path before attempting the same key a second time. That habit is useful in both editors even when the shortcuts are different.

Prepare an original and two scoped copies

The original sample has three lines. We want to keep the report mode and archive visibility as shown and change only the report limit. Use a fresh practice folder so you can identify every file that belongs to the exercise. The subshell sets a restrictive file creation mask for the fixture and keeps your ordinary shell's mask unchanged.

editor_lab=$(mktemp -d "$HOME/editor-lesson.XXXXXXXX") &&
  cd -- "$editor_lab" &&
  (
    umask 077
    printf '%s\n' 'display_mode=summary' 'report_limit=25' 'show_archived=no' > ./original.conf &&
    cp ./original.conf ./nano-draft.conf &&
    cp ./original.conf ./vim-draft.conf
  ) &&
  pwd && ls -l -- ./original.conf ./nano-draft.conf ./vim-draft.conf

Confirm the printed directory begins with your own unique practice directory name. If setup did not finish or printed an error, stop before opening an editor. The three files should have identical visible text and your account should be able to write the two draft files. The original has the same content but serves a different role in the exercise. Leave it as the comparison source. A real versioned backup has its own storage and verification procedure. This sample demonstrates reading from a stable baseline in a disposable place.

cmp ./original.conf ./nano-draft.conf
cmp ./original.conf ./vim-draft.conf
command -v nano
command -v vim

Run the four checks separately. The comparisons ordinarily produce no output if the bytes match. Check a comparison's exit status immediately if you want to record that result. The path lookups answer whether the shell can resolve the editor names in this environment. The execution path and a program's own title can help you identify its implementation. On a system with GNU nano, its help menu describes the keybindings appropriate to that version. If an editor is absent, use the other editor for the lab or follow the steps as a reading exercise. No package change is needed to learn the editing sequence.

Before opening a draft, write down the intended result in words. The old line has the value 25. The new line has the value 50. The first and third lines should have the same text and appear in the same order. This is a small change with clear acceptance conditions. A peer should be able to review the two result files without needing to watch you type. Preparing that check first makes it easier to spot an extra line, an altered setting or a mistaken destination afterwards.

Edit the first copy with GNU nano

GNU nano's usual editing screen lets you type directly into the text at the cursor. It has commands for file operations, search and other actions, generally offered through shortcuts and prompts. The caret in an on-screen shortcut such as ^O conventionally means hold Control and press the letter O. The menu can also show a Meta prefix for some shortcuts, often sent by Alt or an Escape prefix depending on the terminal. Read the labels on your screen because versions, user settings and similar editors can have different bindings.

nano ./nano-draft.conf
  1. Check the filename and the three visible lines. Use the arrow keys to move to the second line, whose entire text is report_limit=25. A classic GNU nano shortcut for search is Ctrl+W. You can enter the old line and press Enter, then confirm the cursor landed on the second line. Moving to it with the arrow keys works even on a system with changed search keys.

  2. With no text selection active, use the displayed cut-line action, commonly Ctrl+K, to cut the old line. Check that the report mode is still first and the archive setting follows it. At the place where the old line was, type report_limit=50 followed by Enter, keeping the archive setting on its own line. If your editor settings cut only a portion of the line, use the visible buffer to correct it before writing. You can edit the two digits directly if you prefer.

  3. Use the Write Out action, commonly Ctrl+O. Check that the confirmation prompt shows ./nano-draft.conf or its correct resolved filename. Press Enter to accept that destination. Wait for the message that the file was written, or read any error shown. An editor prompt that is still waiting for a filename has not completed this step.

  4. Use the displayed exit action, commonly Ctrl+X. Return to the shell and check cat ./nano-draft.conf. The saved text should show exactly the three intended lines. A modified buffer plus a successful return to the prompt does not tell you the result until you inspect the file.

If you are practising cut and paste, use a disposable copy. In the common default bindings Ctrl+U inserts text from the cut buffer at the cursor. This can help undo a cut immediately when that is the only operation you want to reverse. GNU nano also documents an undo action in versions and configurations where the relevant key is available. Use the on-screen help to check it for your version. After undoing in memory, you still decide whether a write should change the saved file. Keep the working and saved observations separate.

If you press Exit while the buffer is modified, the editor can ask what to do. Read the available actions in that prompt. Choose the option to go back if you want to inspect the buffer again. Choose discard only when you intend to lose edits made since the last write. Some default bindings or versions label this choice differently, so the prompt is the best immediate guide. After you exit, compare the file with its expected contents to see which decision took effect.

Edit the second copy by switching Vim modes deliberately

Vim starts in Normal mode under ordinary settings. In this mode key sequences are editing and movement operations. Use i to switch to Insert mode when you want the keys to add characters. Use Esc to return to Normal mode. In Normal mode, typing a colon opens the command line for actions such as writing a file. These modes let short key sequences do more than one kind of work. They also explain the most common beginner confusion about saving. If you type :w while still inserting text, Vim can insert those characters into the buffer.

vim ./vim-draft.conf
  1. Check the filename and the three lines on the screen. Press Esc if you need to make sure you are in Normal mode. Type :set number and press Enter to show line numbers. The numbers in the margin are an editor display setting. They do not become part of the saved text.

  2. Move to the second line with the keys or search in Normal mode. Type /^report_limit=25$ and press Enter to find the complete old line with the default pattern interpretation. Confirm that the cursor is on the match. The caret and dollar sign in the search represent start and end of line in the pattern. If settings affect search or the result is unexpected, use the visible line numbers to move directly to line two.

  3. In Normal mode, type c then c. The common Vim command replaces the current line's contents and enters Insert mode. Type report_limit=50 and press Esc to leave Insert mode. Inspect the three lines. If the wrong line was changed, use the undo action in Normal mode and try again. The change is still in the buffer at this point.

  4. With Normal mode active, type :w and press Enter. Verify the written-file message or read the error. Then type :q and press Enter to leave. If Vim reports unsaved changes, decide whether to write them or discard them after checking what they are. The single command :wq requests a write followed by a quit, which is useful when you can already explain both events.

The u key in Normal mode undoes a change in the buffer. A typical redo key there is Ctrl+R. These actions manipulate edits. For example, after saving the value 50, you might undo it to see 25 again in the editor. Unless you write the updated buffer, the saved file can still hold 50. If you need to intentionally discard the current unsaved changes in this one-file lab, use Esc, then :q! and Enter. That leaves the current buffer without persisting the unsaved changes. It does not erase an earlier successful write.

Vim has built-in help. In Normal mode you can type :help :write, then press Enter. Read the description of the command and check the active help window's label. Close that window with :q from Normal mode to return to the editing view in this example. The help is especially useful when you are unsure whether a command changes one line, a selected range or every match in the file. Prefer a specific intended edit until you have looked at the replacement's scope.

Compare what was written with the starting point

Return to the shell in the lab directory. Compare the original with each edited copy. If you practised one editor, run only the corresponding comparison. The tool produces a unified difference report. The headers identify the file pair and can show timestamps. A minus-prefixed content line was present in the old version and a plus-prefixed content line is present in the new version. Lines shown for context let you see what surrounds the edit. The signs are the difference format's markers. They are not characters the editor added to the file.

diff -u ./original.conf ./nano-draft.conf
diff -u ./original.conf ./vim-draft.conf
 display_mode=summary
-report_limit=25
+report_limit=50
 show_archived=no

The sample shows the important part of each difference. The intended edit adds one line and replaces one old line. If a diff shows another setting changing or a new blank line appearing, inspect it and decide whether that is part of what was approved. The timestamp by itself does not tell you the contents changed in the intended way. A file can be saved with its original contents. A lookup of the exact filename plus the actual comparison gives you better evidence.

When both drafts are available and expected to match, you can compare them byte for byte with cmp ./nano-draft.conf ./vim-draft.conf. If they differ, use the ordinary difference output to locate the visible change. Check line endings and whether there is a final newline if the text appears the same. A file transported from another system can contain a carriage return before a newline. Some editors preserve or convert this depending on settings. A parser's requirements depend on the actual file format. Use the comparison to learn precisely what each editor wrote.

Read the comparison tool's exit status according to its own documentation. For the common diff implementation, zero means no differences, one means differences were found and a larger value indicates an error. A status of one can be the expected result in this exercise. You can capture it in a shell conditional without confusing a detected change with a failed file read. Read the error message and path if the program does fail. A blank terminal alone does not prove the right answer if the input path was wrong.

if diff -u ./original.conf ./vim-draft.conf; then
  comparison_status=0
else
  comparison_status=$?
fi
printf 'Comparison status: %s\n' "$comparison_status"

Run the status example for the draft you actually edited. It should report one after the intended edit, accompanied by the expected line change. To verify the small training format, read the file again and confirm there is one exact setting line with the new value. A real application can need a proper validator that understands its whole file, related files and allowed settings. A difference report answers the comparison question. It is also useful input for a separate validation step before an application consumes the edit.

Look at line endings and whitespace when the screen looks right

Sometimes both people agree about what a file looks like, yet a comparison shows more changes than expected. A terminal editor can display a long line on two screen rows without inserting a new line in the text. It can show tabs as a stretch of blank space. It may display line numbers between the edge of the window and the actual text. These visual aids change how you see the file. Use the saved file and a tool that makes invisible characters apparent when investigating what a parser actually received.

For the training copy, the saved result should contain three lines and a line ending after the last line. We used a command that writes a newline after every original record. You can check the line count and show a visible marker for the ends of the lines with these tools. Run the exact path for the editor you used. The commands below use the Vim draft as the example. The display is safe for this fictional file. Use an appropriate secure input when diagnosing a real configuration that could contain sensitive values.

wc -l ./vim-draft.conf
LC_ALL=C sed -n '1,4l' ./vim-draft.conf

For the intended draft the first command should report three. The second command's list form can show each line followed by a dollar sign marker. The marker is part of the tool's display. An unexpected empty line would show another line with an end marker and no setting before it. A carriage return at the end of a record can be shown as an escaped character. Different implementations can use different escape displays. Check the manual for the exact representation in your environment. Then determine whether your editor changed the line endings or revealed a difference that had already been present.

Suppose the saved line starts with a tab before the key. A quick visual glance may read it as the same setting. Our small validator matches the literal first field and will reject it. A real format might accept indentation, require a particular kind of space or treat it as part of a string. A student who copies a setting from a word processor might also introduce smart quotes or a similar-looking punctuation mark. A plain text editor stores the actual characters typed or pasted. Use the application format to decide whether that character is accepted.

This is also why a difference report should be read against a meaningful original. If several lines changed solely because their endings changed, fix the editing setup or decide explicitly whether that conversion belongs in the task. The colleague who requested a new report limit expects to be able to review one line. For a restored copy, confirm the revision and file attributes as well as its contents. Permissions and ownership are separate pieces of metadata. Two files can contain identical bytes and offer different access to the service account.

Record the precise conclusion in the practice log. For example, “The saved draft has three newline-terminated records. The unified diff shows only the report limit value changed. The parser check found one setting with value 50.” Those tests complement one another. You can repeat them after switching editors because they operate on the resulting file and answer the same questions about both drafts.

Prove that leaving without a write preserves the last saved result

Use the copy you successfully edited. Open it again and verify that it shows the new value 50. Intentionally add a short scratch line at the end of the buffer. You are going to leave that line unwritten. In GNU nano, choose Exit and select the on-screen action that discards the modified buffer. In Vim, press Escape, then enter :q! while using the simple one-buffer editing session. After the editor closes, read the file again from the shell. The report limit should still be 50 and the scratch line should be absent.

This process demonstrates two useful limits of a discard action. The unwritten scratch line stays out of the file. The older value 25 does not return merely because you chose to discard a later edit. It was already replaced during your earlier write. If you are asked to restore a previous value after a save, recover it from an identified earlier version and write or deploy it through the appropriate procedure. A versioned source or a verified backup lets you determine what that value was without relying on memory.

For a second observation, reopen the draft and change the new value to a visibly incorrect number. Undo the change in the buffer using your editor's documented action, then verify what you see. If all edits are gone, many editors no longer ask to save. Some maintain a modified indicator based on their own undo state. Decide explicitly whether to keep the existing saved file. The purpose is to see which changes were only proposals in memory and which were written. A teammate outside that editor session can read only the file you actually saved.

Read-only viewing tools are often appropriate when your job is inspection. If all you need is to confirm a setting, use a bounded file viewer or the relevant read-only status tool. Editors retain a working context in which a key can alter the buffer and support additional write operations. A view-only option can create an extra check before write, but the underlying file permissions and tool policy are separate. Write down whether the current step is inspection, editing, validation or deployment. You can then choose an interface suited to the step without needing to solve all four at once.

Diagnose a refused save or a recovery warning

Suppose the editor can display the file but reports Permission denied when you save. Reading and writing require different permissions. Check that you opened the intended destination from the expected directory. List the file and any relevant parent directory. An editor can write through a temporary replacement file, create a backup, use a swap file or choose a different write technique based on settings. Some of those operations require access to the directory even when a program could append directly to the existing file. Learn which operation failed instead of assuming the same error applies to everything in that directory.

A controlled practice exercise runs on files you own. If a real configuration is maintained by another account, use its authorized editing workflow. An editor started with broad administrative authority can execute more actions than editing one file. On a shared system there may be a managed configuration repository or a reviewed deployment process. Ask the service owner which is the source of truth. An edit to a generated file might be overwritten on the next deployment, even if it saved correctly. The ability to change a path is separate from choosing the right place to make the change.

Vim can display a swap warning when it detects a possibly existing edit session or recoverable work. The warning can include the original name and information about the saved swap. Read it before choosing an action. Another editor might still be working on the file. A crashed session can leave recoverable edits. In a shared setting, coordinate with the current editor and preserve the original and recovery information. Use Vim's documented recovery procedure when appropriate and compare the recovered text with the saved version before replacing either. Deleting a warning's referenced file can discard the evidence you need.

Another learner sees characters such as :wq in the text. That suggests the keystrokes may have been sent while the editor was in Insert mode. Do not assume that this content was saved. Press Escape and look again. Undo the unwanted edit, restore the intended line and save only if the current buffer is correct. After exiting, use a fresh read of the exact target and check the diff. If the text appears correct in the editor but the original is unchanged on disk, consider a failed write, a different destination and an intentionally discarded buffer.

You can use this short troubleshooting sequence. Identify the current file and cursor mode. Read the exact message from the previous operation. Confirm that you have permission for the intended action under the account doing the work. Choose a harmless verification step before repeating a write. This sequence reduces the chance of overwriting the wrong file while trying to recover your place, and gives you a useful observation to share if you need assistance.

Validate the file before a real program uses it

For the fictional report setup, we want the setting to occur exactly once with the intended value. The rest of the file should match the original. The following check assumes the sample uses a simple equals sign between name and value. It checks one property of the text file and prints a clear result. Choose the path of the draft you actually wrote. This command does not start a report service or edit the draft.

awk -F '=' '
  $1 == "report_limit" { count++; value=$2; fields=NF }
  END {
    if (count == 1 && fields == 2 && value ~ /^50$/) {
      print "Validated one report limit with value 50"
      exit 0
    }
    print "Check the report limit entry"
    exit 1
  }
' ./vim-draft.conf

The first part separates each line into fields at each equals sign. When the first field matches the setting name, the check records its value and the field count. The final check confirms that the key occurred once and has the expected value in the simple format. For example, appending a second setting line can make a visual search appear successful while leaving the configuration ambiguous. The fixture check refuses that duplicate. The diff covers a second property by showing any unrelated edit around the report's two other settings. Neither result establishes that this format is supported by a real program. The program's own validator is the appropriate evidence for that.

Now imagine applying an approved configuration change on a learning service with its own validation procedure. Establish the path the service uses and any included files. Save a versioned copy or use the configuration source as directed by the service owner. Test the new candidate with the documented validator. Some services must reload the validated settings before requests see a change. Other programs read the file at startup or on each request. A successful write only changes what is on disk, and a successful configuration check only answers what the validator tests. Confirm the observable behavior with a small trial request after the approved deployment step.

For the training example, a good handover says “I changed report limit from 25 to 50 in the draft. The diff shows one setting replacement. The fixture validator found one instance of that setting with the correct value.” If someone then asks whether visitors see 50 entries, you know which additional piece is missing. Verify how the intended program loads the file and check the actual report using an authorized test. Stating that distinction keeps a saved change from being mistaken for a completed release.

Close the editors and clear the named practice files

Return to the shell after exiting any editor windows used for this exercise. Check the working directory and list its contents first. The removal below prompts for the three exact fixture files. It uses an empty-directory removal so an unexpected backup or temporary file will keep the directory available for inspection. If you want to keep the resulting diffs for practice, keep the lab folder instead.

pwd
ls -la -- .
if [ -n "$editor_lab" ] && [ "$(pwd -P)" = "$(cd -- "$editor_lab" && pwd -P)" ]; then
  rm -i -- ./original.conf ./nano-draft.conf ./vim-draft.conf &&
    cd -- "$HOME" &&
    rmdir -- "$editor_lab"
fi

Answer each prompt only when it lists a path you intentionally created for the exercise. If the final command reports that the directory is not empty, identify the extra item first. A startup setting may have enabled backups or added an editor cache. Verify which program created it and whether it contains edits you wanted to keep. Do not remove a warning or recovery file you do not recognize just to make a cleanup command succeed. When the directory is empty, the removal leaves your shell in your home directory.

Interview questions with worked answers

What happens between typing in an editor and changing a saved configuration?

The editor displays a working buffer. I can change the buffer without writing it. An explicit successful save writes the selected destination. I then read that exact path and check a diff against an identified prior version. A separate application validation and load step may be necessary before service behavior changes.

Why does Vim sometimes insert the characters of a command into a file?

The editor may be in Insert mode. In that mode typing adds characters to the buffer. I return to Normal mode with Escape before entering a colon command. If unwanted characters appeared, I inspect and undo them before any write, and verify the disk result after exit.

What could explain an editor saying no to a save while it can read the file?

The account might have read permission without write permission. The editor may also need a writable parent for a replacement or a backup. I check the exact operation and the saved path, inspect the target and parent and follow the file owner's editing workflow. A similar filename elsewhere is insufficient evidence.

What does a difference report with one old line and one new line prove?

It shows the text found in the two files and where that line differs. A carefully prepared sample can let me verify that only the intended line changed. It does not run the application's rules or prove that a service loaded the newer file. I would validate the candidate and verify the live behavior separately.

A colleague closed Vim and later saw a swap warning. What should they check?

First determine whether another editing session is active or whether there are recoverable edits left by a failed session. Preserve the evidence and use the editor's documented recovery workflow. Save recovered content to an appropriate separate path and compare it before replacing the known file. This avoids overwriting a teammate's work.

Check your understanding

1. You are fixing one setting in a draft file. Which pair best confirms the intended edit?

A. The editor accepted a key and the date changed.
B. The saved path is the exact draft and the diff has the one expected replacement.
C. Two terminal windows are open.

Answer and reasoning

B. Path and content evidence tell you where the change happened and what was written. A displayed editor status can help explain the steps but does not replace this check.

2. What does writing and then discarding a later edit do in the single-file exercise?

A. It leaves the previously written version on disk.
B. It restores the original version automatically.
C. It deletes the file's parent directory.

Answer and reasoning

A. The later discard applies only to the unwritten changes. A prior successful save persists until another write or approved restoration.

3. Why would a beginner check the filename during Write Out?

A. It shows which process used the most CPU.
B. It changes the file encoding every time.
C. It identifies the destination before a persistent write.

Answer and reasoning

C. Several directories can contain the same name, and a typo can create a new file. Confirm the intended destination before accepting the prompt.

4. In which Vim mode can ordinary letters enter text into the buffer?

A. Insert mode
B. The shell's interactive prompt after exiting
C. The command line after a colon always adds to the file

Answer and reasoning

A. Use Escape to return to Normal mode before typing the editor's colon commands. Check your mode if the characters appear in the document.

5. What can explain an expected diff status of one?

A. The command automatically installed a new editor.
B. It found the intended differences between the files.
C. The reported file writes were definitely refused.

Answer and reasoning

B. A comparison with differences is the expected outcome after the exercise's edit. A file-open error needs a separate diagnostic and status.

Revision cards

Buffer and disk are separate

Typing changes the working buffer. A successful write saves to a path. Read that path separately to verify the result.

Ask the Nano prompt

Read the shortcut label for your environment. When writing out, verify the destination and the success or error message before exiting.

Vim mode changes keys

Use Insert mode to type text. Press Escape to use Normal mode. From there, the colon opens a command line for writing and quitting.

Discard affects unwritten edits

A prior write persists. Practise discarding a later scratch line and confirm the earlier saved value from the shell.

Check exact properties

Diff reports the textual change. A format validator checks selected rules. Verify the actual application separately when the file is deployed.

Preserve evidence for recovery

Read swap and permission messages before acting. Check for an active teammate or an earlier recoverable session, then compare saved and recovered versions.

Official references