Editing Text Files and Archiving
Edit configuration files in nano and survive vim, make safe backups before changes, and bundle and compress files with tar and gzip.
Welcome back!
Step 1 of 12Learn
Everything is a text file
On a Linux server, nearly every setting lives in a plain text file: the web server's configuration, the list of users, scheduled jobs, the SSH settings. Changing how the system behaves usually means opening a text file in /etc, editing a line and restarting a service. So you need a terminal text editor.
nano is the friendliest. Run nano notes.txt and start typing. The bottom two lines show shortcuts, where ^ means Ctrl:
- Ctrl+O writes (saves) the file; press Enter to confirm the name.
- Ctrl+X exits; if there are unsaved changes, nano asks whether to save.
- Ctrl+W searches ("where is"), Ctrl+K cuts a line, Ctrl+U pastes it.
That's enough to edit any config file. Before you edit an important one, make a copy: cp sshd_config sshd_config.bak. If your change breaks something, mv the backup back into place and you are exactly where you started. Many teams also add a dated suffix, such as sshd_config.2026-03-14, so they can tell backups apart.
System files in /etc belong to root, so you will open them with sudo nano /etc/hosts. You will learn exactly what sudo does in the permissions module.
Step 2 of 12Learn
Surviving vim
Sooner or later a command will drop you into vim (or its ancestor vi), because it is installed on almost every Unix-like system and is the default editor for tools like git and crontab. Vim is powerful, but it surprises newcomers because it has modes.
- Normal mode is where vim starts. Keys are commands, not text:
xdeletes a character,dddeletes a line,uundoes. Typing a sentence here causes chaos. - Insert mode is for typing text. Press
ito enter it; "-- INSERT --" appears at the bottom. Press Esc to go back to normal mode. - Command-line mode starts when you press
:in normal mode. This is where you save and quit.
The survival kit:
| Keys (from normal mode) | Effect |
|---|---|
i | start inserting text at the cursor |
| Esc | return to normal mode |
:w then Enter | write (save) |
:q then Enter | quit (fails if there are unsaved changes) |
:wq then Enter | save and quit |
:q! then Enter | quit and throw away changes |
/word | search for "word" |
If you are ever stuck, press Esc twice and type :q!. You lose unsaved edits but you are out. You can set a friendlier default editor for tools like git with export EDITOR=nano.
Step 3 of 12Practice · Diagram
The three modes of vim
Most vim confusion comes from typing in the wrong mode. Tap each mode.
In which mode does pressing dd delete a whole line?
Tap the shape that answers the question, then press Check.
- vim
- Normal mode
Where vim starts. Keys are commands:
x,dd,u. Esc always brings you back here.- Insert mode
Press
ifrom normal mode. Keys type text. "-- INSERT --" shows at the bottom.- Command-line mode
Press
:from normal mode. Typew,q,wqorq!and press Enter.
Step 4 of 12Practice · Put in order
You opened config.yml in vim and need to change one value and save. Put the steps in order.
Drag the items, or use the arrow buttons, to put them in order.
- Move the cursor to the value you want to change
- Type the new value
- Press Esc to return to normal mode
- Type :wq and press Enter
- Press i to enter insert mode
Step 5 of 12Flashcards
Editor survival card
Tap a card to flip it.
Step 6 of 12Practice · Choose one
In vim you typed some text, pressed Esc, and now want to leave without saving your changes. What do you type?
Step 7 of 12Learn
Bundling and compressing with tar
To back up a directory, send a project to a colleague or download software, you will meet archives. On Linux the standard tool is tar (originally "tape archive"). It bundles many files and directories into one file and, with an extra option, compresses it.
The options read like a recipe:
ccreate an archive,xextract one,tlist its contentszcompress or decompress with gzipvverbose: print each file name as it goesfthe next argument is the archive file name
So:
$ tar -czvf site-backup.tar.gz /var/www/site # create
$ tar -tzf site-backup.tar.gz # look inside
$ tar -xzvf site-backup.tar.gz -C /tmp/restore # extract into /tmp/restoreThe .tar.gz (or .tgz) extension means "a tar bundle compressed with gzip". gzip file on its own compresses a single file into file.gz and removes the original; gunzip file.gz reverses it. Text such as logs, code and CSV often shrinks to a quarter of its size or less, while photos and videos, which are already compressed, barely shrink at all.
Two habits: list an archive with -t before extracting it, so you know whether it will spill hundreds of files into the current directory, and use -C to extract into a specific folder.
Step 8 of 12Practice · Chart
How much gzip shrinks different files
Size after compression as a percent of the original. Text has lots of repetition; photos and video are already compressed.
Which file type shrinks the most?
Tap the bar that answers the question, then press Check.
Step 9 of 12Note
Step 10 of 12Practice · Fill in the blanks
Fill in the blanks
To create a gzip-compressed archive called logs.tar.gz from the directory logs, run `tar - logs.tar.gz logs. To extract it, you would replace the letter c` with .
Step 11 of 12Practice · True or false
Compressing a folder of JPEG photos with gzip will usually make it about four times smaller.
Step 12 of 12Practice · What would you do?
What would you do?
You need to change the port in /etc/myapp/app.conf on a production server. The service must keep working if you make a mistake. What is the best approach?
Lesson complete!