wEEK 6

Text Files and Editors (nano & VIM)

Why Text Editing Matters in Linux

When managing servers, you often won’t have a GUI editor. You’ll need tools like nano and VIM. Mastering these editors—and knowing supporting tools like cat, less, diff, and grep—is essential for system administrators and developers.

T.E.X.T.O.R. Framework

T — Text Files

Text files are the foundation of Linux work: configs, scripts, logs, and documentation. The essential skill is not just creating them but controlling how content is written.

Appending (>>) preserves existing content, useful for logs or adding incremental notes. Overwriting (>) wipes the file and replaces it entirely — dangerous if done unintentionally but powerful when resetting files.

OperationExampleUse Case
Appendecho "Adding entry" >> logfile.txtExtend logs or notes without losing prior lines.
Overwriteecho "Reset config" > settings.txtReplace contents entirely when rebuilding a config.
Viewcat file.txtQuick inspection of small files.

E — Editors

Once files grow beyond a few lines, an editor becomes indispensable.

  • Nano excels at simple edits, with commands like Ctrl+O (save) and Ctrl+X (exit). Its strength is approachability.

  • VIM demands more learning: i to enter insert mode, :w to save, :q to quit. But in return, it offers unmatched power, especially for navigating and editing large files.

TaskNanoVIMProfessional Note
Open filenano notes.txtvim notes.txtUse nano for short notes, vim for configs/code.
Save changesCtrl+O:wBoth must write to disk explicitly.
ExitCtrl+X:q, :wq, :q!VIM’s flexibility makes it harder to quit, but safer against mistakes.

 

X — Explore Editing

Editing means more than typing — it’s about choosing the right strategy for the situation.

  • Appending in Linux (>>) or VIM’s A command lets you build on existing notes without disturbing old data.

  • Overwriting (>) or deleting (dd) wipes content to make way for new text.

  • Replace mode (R in VIM) is valuable when updating blocks of code or parameters without retyping everything

ActionNano/LinuxVIMWhy It Matters
Appendecho "log" >> fileA (append at end of line)Safe way to add notes or logs.
Overwriteecho "reset" > filedd (delete line) then insert textRebuild content from scratch.
Replace one charrQuick fixes, like correcting typos in configs.

 

Navigate the tree​

T — Try Other Tools and Inspect Differences

Not every task requires editing. System admins often just need to inspect and compare.

  • less is the standard tool for paging through long files without editing them.

  • wc (word count) quickly reveals line or word counts, often used to check log size or validate dataset length.

  • Inside VIM, navigation commands (Ctrl+f for forward, Ctrl+b for back, H/M/L for positions) let you skim huge files efficiently.

  • The diff command shows line-by-line differences.

  • VIM offers visual diff mode (:diffsplit), letting you see two files side by side.

 
ToolExampleUse Case
lessless /var/log/syslogScroll through system logs.
wcwc -l data.csvCount lines in a dataset.
VIM navigation42G, Ctrl+fJump to exact line numbers in error messages.
ToolExampleWhy It Matters
diffdiff config.old config.newVerify what changed before deploying.
vimdiffvim -d file1 file2Professional-grade comparison with highlighting.

O — Organize Files

Organization prevents mistakes. Professionals don’t keep all versions in one pile — drafts, finals, and backups must be separated.

CommandExampleWhy It Matters
mkdirmkdir drafts finalKeeps experimental vs production versions apart.
mvmv notes.txt drafts/Separates active work from finished copies.
ls -Rls -R project/Shows full project tree at once



R — Review with Search

Troubleshooting is often about finding the line.

  • With grep, you can scan logs or configs for keywords in seconds.

  • With VIM’s /pattern, you can jump directly to the next occurrence of a string inside a file, repeating with n.

ToolExampleWhy It Matters
grepgrep "error" /var/log/syslogPinpoints lines with “error” in logs.
grep -ngrep -n "server" config.txtShows line numbers for fast navigation.
VIM search/error, ?errorNavigate large configs or codebases directly.

This concludes Lecture 6. Please return to Blackboard to access the Week 6 materials.

Scroll to Top