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.
- Configuration files (/etc/ssh/sshd_config, /etc/fstab)
- Code and scripts (.py, .sh, .c)
- Logs and documentation
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.
| Operation | Example | Use Case |
|---|---|---|
| Append | echo "Adding entry" >> logfile.txt | Extend logs or notes without losing prior lines. |
| Overwrite | echo "Reset config" > settings.txt | Replace contents entirely when rebuilding a config. |
| View | cat file.txt | Quick 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) andCtrl+X(exit). Its strength is approachability.VIM demands more learning:
ito enter insert mode,:wto save,:qto quit. But in return, it offers unmatched power, especially for navigating and editing large files.
| Task | Nano | VIM | Professional Note |
|---|---|---|---|
| Open file | nano notes.txt | vim notes.txt | Use nano for short notes, vim for configs/code. |
| Save changes | Ctrl+O | :w | Both must write to disk explicitly. |
| Exit | Ctrl+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’sAcommand lets you build on existing notes without disturbing old data.Overwriting (
>) or deleting (dd) wipes content to make way for new text.Replace mode (
Rin VIM) is valuable when updating blocks of code or parameters without retyping everything
| Action | Nano/Linux | VIM | Why It Matters |
|---|---|---|---|
| Append | echo "log" >> file | A (append at end of line) | Safe way to add notes or logs. |
| Overwrite | echo "reset" > file | dd (delete line) then insert text | Rebuild content from scratch. |
| Replace one char | — | r | Quick 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.
lessis 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+ffor forward,Ctrl+bfor back,H/M/Lfor positions) let you skim huge files efficiently.
The
diffcommand shows line-by-line differences.VIM offers visual diff mode (
:diffsplit), letting you see two files side by side.
| Tool | Example | Use Case |
|---|---|---|
| less | less /var/log/syslog | Scroll through system logs. |
| wc | wc -l data.csv | Count lines in a dataset. |
| VIM navigation | 42G, Ctrl+f | Jump to exact line numbers in error messages. |
| Tool | Example | Why It Matters |
|---|---|---|
| diff | diff config.old config.new | Verify what changed before deploying. |
| vimdiff | vim -d file1 file2 | Professional-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.
| Command | Example | Why It Matters |
|---|---|---|
| mkdir | mkdir drafts final | Keeps experimental vs production versions apart. |
| mv | mv notes.txt drafts/ | Separates active work from finished copies. |
| ls -R | ls -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 withn.
| Tool | Example | Why It Matters |
|---|---|---|
| grep | grep "error" /var/log/syslog | Pinpoints lines with “error” in logs. |
| grep -n | grep -n "server" config.txt | Shows line numbers for fast navigation. |
| VIM search | /error, ?error | Navigate large configs or codebases directly. |
This concludes Lecture 6. Please return to Blackboard to access the Week 6 materials.