echo
print a line — your first act of writing
Echo prints back whatever you give it. Looks useless until you realize output doesn't have to go to the screen — it can go anywhere you point it. That's the finale of this page. For now, this is the shell's way of saying something.
echo hello, terminal
hello, terminal
echo $HOME prints your home directory — it's how you peek at variables, not just words.
touch
make an empty file
mkdir makes a folder; touch makes a file. An empty one, nothing in it yet. Folders and files are how the tree is built, and now you're building.
touch notes.txt
ls
notes.txt
touch also updates a file's "last modified" date — hence the name, like reaching out and tapping it.
cp
copy a file
Two arguments: the thing you're copying, then where it's going. Keep a backup before you start changing something — it's cheap insurance, and it only takes a second.
cp notes.txt notes-backup.txt
ls
notes.txt notes-backup.txt
cp -r copies a whole directory, contents and all — r for recursive.
mv
move — and here's the trick, rename
Moves a file from one place to another. The surprise that trips every beginner: Linux has no separate "rename" command, because moving and renaming are the same thing — a file's name is just its address. Move it to a new name in the same folder, and you've renamed it.
mv notes.txt todo.txt
ls
notes-backup.txt todo.txt
mv is instant within the same filesystem — it changes the label, not the contents.
rm
remove — and there is no recycle bin
Deletes a file. Not "moves it to a trash folder" — deletes it. Gone. The command line doesn't second-guess you, and that's a feature: no shadow copies, no "are you sure?", just done. Which is exactly why you made a backup with cp two commands ago. Measure twice.
rm notes-backup.txt
ls
todo.txt
rm -rf is the one with the legends attached — remove a directory and everything inside it, f for "don't ask, just do it." It will happily eat your whole home directory if you point it wrong. Treat it with respect, and never type it tired or angry.
grep
search inside files — the finder
Searches text. Give it a word and a file and it prints every line that matches. This is the command you'll reach for more than any other once you have real files — logs, configs, code. First, let's put some text in our file:
echo remember: water the transplants > todo.txt
grep water todo.txt
remember: water the transplants
that > is redirection — it sends echo's output into a file instead of the screen. We'll get there properly at the bottom of this page.