Skip to contentExploitQuest

Making, Reading, and Carefully Deleting

A handful of verbs — make, look, copy, move, remove — do most of the daily work. One of them has no undo, and this is where you learn to respect it.

4 min readNot yet reviewed
Wrenlearner

I can move around now. But I have not actually done anything to a file.

Rookmentor

Time to. Five small commands cover most of daily life. Four are gentle. One deletes with no confirmation and no recycle bin, and we will treat it with the respect it demands.

Making and looking

you@linux
you@linux:~$ mkdir project

Make a directory to work in.

you@linux:~$ cd project

Step into it. Watch the prompt — it always tells you where you are.

you@linux:~/project$ touch ideas.txt

Create an empty file. touch also just updates the timestamp of one that exists.

you@linux:~/project$ echo "encrypt the backups" > ideas.txt

Write a line into it. The `>` sends the output to the file instead of the screen.

you@linux:~/project$ cat ideas.txt
encrypt the backups

Now you — read the file straight back to the screen.

cat  file      -> dump a whole (short) file to the screen
less file      -> page through a long file; q to quit
head file      -> just the first lines
tail file      -> just the last lines; tail -f follows a growing log
  1. Line 1cat is fine for a few lines. For anything long it floods the screen — reach for less instead.
  2. Line 4tail -f is the one you will love later: it shows a log file live as new lines arrive, which is how you watch a program while it runs.

Copying and moving

cp copies a file (cp a.txt b.txt leaves both). mv moves it, which is also how you rename — moving old.txt to new.txt in the same folder is a rename. Both are everyday, both are reversible enough. Then there is the one that is not.

The dangerous one, and how professionals stay safe
# remove a single file — gone immediately, no bin
$ rm ideas.txt
# the infamous flags: -r recurse into folders, -f force, no questions
# rm -rf deletes an entire tree silently. Never run one you did not read.
# safer habit: list first with ls, THEN delete what you just saw
$ ls *.tmp
old1.tmp  old2.tmp
$ rm *.tmp

Why is "list it first, then delete" more than just fussiness?

You want to rename report.txt to report-final.txt. Which command?

Deleting on autopilot

- Typing rm -rf from memory and pressing enter
- Using a wildcard without checking what it matches
- Assuming there is a recycle bin to save you

Deleting deliberately

- Read the whole line before enter, especially with rm
- ls the pattern first, then rm the same pattern
- Keep backups, so a mistake is an annoyance, not a disaster

Respect for rm is not a beginner's nerves you grow out of. The most experienced people are the most careful with it, because they have seen what it does.

Wrenlearner

So four friendly verbs and one that needs a steady hand.

Rookmentor

Make, look, copy, move — and remove, read twice. With those you can do real work. And the steady hand with rm is a habit you keep for the rest of your life at a keyboard.

Magpieadversary

I have watched more damage done by a careless rm than by any attack I ever ran. The keyboard in your own hands is the most dangerous one.

Make one yourself

Your turn

Create a file called ideas.txt with the word encrypt in it, then read it back to prove it is there. Two commands.

you@practice
Practice shell — nothing here is real. Type 'help' to begin.

So a few verbs — mkdir, touch, cat, less, cp, mv, and a respected rm — cover most daily work in the shell. That completes The Terminal: you can converse with the machine, move through its one tree, and make, read and remove the files in it. The next chapter puts these to work — combining commands into something greater than any one of them: pipes.