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.
I can move around now. But I have not actually done anything to a file.
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
Make a directory to work in.
Step into it. Watch the prompt — it always tells you where you are.
Create an empty file. touch also just updates the timestamp of one that exists.
Write a line into it. The `>` sends the output to the file instead of the screen.
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
- Line 1
catis fine for a few lines. For anything long it floods the screen — reach forlessinstead. - Line 4
tail -fis 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.
# 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?
*.tmp might match more than you think — a stray space, as in rm * .tmp, means "delete everything, and also .tmp". Running ls with the exact pattern first shows you precisely what will be hit. You are not being timid; you are confirming the target before firing a weapon that has no safety.You want to rename report.txt to report-final.txt. Which command?
mv moves a file, and moving it to a new name in the same place is exactly a rename — one file, new name. cp would leave you with two copies; rm would just destroy it. Rename is a move.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 youDeleting 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 disasterRespect 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.
So four friendly verbs and one that needs a steady hand.
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.
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
Create a file called ideas.txt with the word encrypt in it, then read it back to prove it is there. Two commands.
Legal
Create, read and delete freely on your own machine. On any system you do not own, deletion is exactly the kind of change that requires explicit authorisation — rm on someone else's files without it is damage, not practice.
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.