3.3 Create and Edit Text Files
Key Takeaways
- RHCSA configuration work is mostly text files: create them with redirection or editors, and ensure paths and ownership match the task so settings persist across reboot.
- vim is the classic exam editor: i/a for insert, Esc then :wq to save and quit, :q! to abandon, /pattern to search; know enough to edit under pressure without a GUI.
- nano is a simpler alternative when available; on-screen shortcuts (Write Out, Exit) speed small edits if you prefer them.
- tilde (~) expands to the current user's home—/home/user for ordinary accounts and /root for root—so always verify whoami and $HOME before writing "into home".
- Creating a file is not enough for services: edit the correct persistent path under /etc (or unit drop-ins), then enable/restart the service so the change is active after reboot.
Almost every RHCSA objective eventually reduces to creating or editing a text file in the right place with the right content, then making related services or permissions correct so the result survives reboot. Shells, package tools, and systemd matter—but if you cannot reliably open, change, save, and verify a file under time pressure, later topics become unnecessarily hard.
Creating Files Without an Interactive Editor
You do not always need vim. Quick creation methods:
touch /tmp/notes.txt # empty file (or update timestamps)
echo 'servera' > /tmp/hostname-hint.txt
echo 'line two' >> /tmp/hostname-hint.txt # append
cat > /tmp/motd-snippet.txt << 'EOF'
Welcome to the lab system.
EOF
Redirection review (ties to essential shell skills):
| Operator | Effect |
|---|---|
> | Write stdout; truncate existing file |
>> | Append stdout |
2> | Redirect stderr |
&> or >file 2>&1 | Combined streams (style may vary; know the idea) |
Danger: > on an existing config file wipes it. For live /etc files, prefer an editor with an explicit save, or write to a temp file and mv into place after review.
Create directories first when needed:
mkdir -p ~/lab/configs
printf 'PermitRootLogin no\n' > ~/lab/configs/sshd-snippet.conf
Choosing an Editor on the Exam
RHEL provides multiple editors. For EX200, fluency in one reliable terminal editor is enough; many candidates standardize on vim (or vi) because it is always expected on minimal systems. nano is friendlier if installed and allowed in your lab image—confirm with command -v nano.
You are not graded on editor fandom. You are graded on the resulting file content and system behavior.
vim Essentials for RHCSA
vim (and vi) is modal.
Modes you must know
| Mode | How you get there | What you do |
|---|---|---|
| Normal (command) | Default on open; Esc from insert | Navigate, delete, yank, type : commands |
| Insert | i (before cursor), a (after), o (new line below) | Type text |
| Command-line | : from normal mode | :w, :q, :wq, :q!, searches |
Survival cheatsheet
vim /etc/hosts
i insert text
Esc back to normal mode
:w write (save)
:q quit
:wq or ZZ save and quit
:q! quit discarding changes
dd delete current line (normal mode)
x delete character under cursor
/ssh search forward for ssh
n next search match
u undo
Open at a line if you know it: vim +42 /etc/ssh/sshd_config.
If you accidentally enter a mode you do not understand, press Esc until you are calm, then :q! to abandon or :wq to save intentionally. Panic-quit without saving can lose work; panic-save of a half-edited sshd_config can lock you out—use sshd -t after SSH edits when that file is in play.
Minimal visual workflow
vim file- Move with arrows or
h j k l i→ type →Esc:wqcat -n fileorgrepto verify
That five-step loop is enough for most exam edits.
nano Essentials
If nano is available:
nano /etc/hosts
Shortcuts are shown at the bottom (^ means Ctrl):
- Ctrl+O — write out (save); confirm filename
- Ctrl+X — exit (prompts if unsaved)
- Ctrl+W — search
- Ctrl+K / Ctrl+U — cut / paste line-oriented workflow
nano stays in a single modeless-style editing experience, which some candidates prefer under stress. Either editor is fine; pick one and practice until saving is automatic.
Paths, Tilde, and Root’s Home
Shell expansion of ~ depends on the current user:
| Identity | ~ expands to | Example personal SSH dir |
|---|---|---|
student | /home/student | /home/student/.ssh |
root | /root | /root/.ssh |
Mistakes that cost time:
- Creating
authorized_keysunder/home/root(wrong; does not exist by default) - Editing
~/my.confas root thinking it is the same file student created earlier - Using relative paths after
cdsomewhere unexpected
Always:
whoami
echo $HOME
pwd
realpath ./file # when available, resolve absolute path
System configuration almost always lives under /etc, unit files under /etc/systemd/system, and application data in documented paths—not in a random home directory—unless the task explicitly says otherwise.
Editing for Persistence After Reboot
Creating a file in /tmp is often non-persistent across reboot (tmpfs or cleanup policies). Exam tasks that must remain after reboot usually require files in durable locations:
| Goal | Typical durable location |
|---|---|
| Service / daemon options | /etc/... or drop-in under /etc/systemd/system/name.service.d/ |
| User shell customization | ~/.bashrc, ~/.bash_profile (per user) |
| Scheduled jobs | /etc/cron.* or user crontab (later objectives) |
| Network and SSH server policy | /etc/ssh/sshd_config, /etc/ssh/sshd_config.d/*.conf |
Workflow for a persistent service-related edit:
- Edit the correct file with vim/nano
- Validate syntax if a tool exists (
sshd -t,nginx -t,systemd-analyze verify, etc.) systemctl enableand/orrestart/reloadas required- Confirm with
systemctl statusand a functional test - Mentally (or literally) ensure a reboot would still load that unit and file
The file content alone does not start a service; enabled units + correct on-disk config produce post-reboot behavior.
Permissions and Safety While Editing
- Ordinary users cannot write most of
/etc; use root (su -or sudo) when required. - Avoid leaving world-writable config files.
- For critical files, copy a backup first:
cp -a /etc/ssh/sshd_config /root/sshd_config.bak - Use
visudofor sudoers (special validation)—do not casuallyvim /etc/sudoerswithout the wrapper when policy tools exist.
View files safely:
less /var/log/messages
cat -A file # show tabs/line endings when debugging weird parse errors
grep -n Pattern file
Practical Exam Patterns
Pattern A — Create a required file with exact content
cat > /etc/issue.d/lab.issue << 'EOF'
Authorized use only.
EOF
Pattern B — Change one directive in a large config
vim /etc/ssh/sshd_config
# set or adjust a directive, Esc, :wq
sudo sshd -t && sudo systemctl reload sshd
Pattern C — Drop-in override instead of editing vendor file
Many modern RHEL configs support .d directories. Prefer a small drop-in when the task allows clarity and safer upgrades—still a text file you create and edit.
Common Pitfalls
- Saving the file under the wrong path or wrong user’s home
- Forgetting to leave insert mode before
:wq(vim beeps or inserts punctuation into the file) - Using
>and truncating a working configuration - Editing only a runtime copy or tmp location that disappears after reboot
- Not verifying with
cat/grepafter the editor exits
Build muscle memory: open → edit → save → verify → enable/restart if needed. That loop is the daily language of RHCSA administration and the foundation for storage, networking, security, and software objectives that all depend on correct on-disk text.
In vim, you have finished editing and are still in insert mode. What is the correct sequence to save the file and exit?
You are root. Which path does the shell use for ~ when you run echo ~ ?
Which approach best creates a multi-line text file with known content using only the shell (no interactive editor)?
You edited a daemon's configuration under /etc and need the change to be used after the next reboot as well as now. What else is typically required beyond saving the file?