shellstreak

Basic terminal commands for beginners

Updated · Every command on this page ran in our practice shell

Short answer

pwd shows where you are, ls lists what's here and cd folder moves you. mkdir makes folders, touch makes empty files, cp copies, mv moves or renames and rm deletes (there's no undo). cat, head and tail show what's in a file.

You only need about a dozen commands to get around a terminal comfortably. Each example below ran in a practice shell; type into the mini terminal under it to try it yourself. Nothing you type here touches your computer.

See where you are with pwd and ls

pwd (print working directory) prints the folder you're in. ls lists what's inside it. Your prompt shows the same place in short form: ~ means your home folder.

example
learner@shellstreak:~$ pwd
/home/learner

List a folder's contents

Give ls a folder name to look inside it without moving. ls -a includes hidden files (names starting with a dot), plus . (this folder) and .. (the one above). ls -l adds details like size and date, ls -lh shows sizes like 4.0K, and ls -F marks folders with a /.

example
learner@shellstreak:~$ ls -a
.
..
.bashrc
Documents
Downloads
notes.txt
projects
todo.txt

Move around with cd

cd folder moves you into a folder. A relative path like projects/website starts where you are; an absolute path like /home/learner/projects starts at the top of the filesystem. cd .. goes up one level, cd ~ (or just cd) goes home, and cd - jumps back to the previous folder.

example
learner@shellstreak:~/projects/website$ cd projects/website && pwd
/home/learner/projects/website

Make folders and files with mkdir and touch

mkdir name creates a folder. mkdir -p a/b/c creates the whole chain, including missing parents. touch file creates an empty file (or updates the date on an existing one). tree draws the result. To put text in a file, echo "Hello" > hello.txt writes the line into hello.txt (replacing anything already in it), and cat hello.txt prints it back.

example
learner@shellstreak:~$ mkdir -p photos/2026 && touch photos/2026/beach.txt && tree photos
photos
`-- 2026
    `-- beach.txt

2 directories, 1 file

Copy, move and rename with cp and mv

cp source copy copies a file; cp -r copies a folder and everything in it. mv moves a file into another folder, and it's also how you rename: mv old.txt new.txt. Both overwrite an existing file with the same name without asking.

example
learner@shellstreak:~$ cp todo.txt todo.bak && mv notes.txt notes-old.txt && ls
Documents
Downloads
notes-old.txt
projects
todo.bak
todo.txt

Delete with rm, rm -r and rmdir

rm file deletes a file. rm -r folder deletes a folder and everything inside it. rmdir folder only deletes empty folders, which makes it the safer choice when you expect a folder to be empty. There's no trash can: deleted means gone.

example
learner@shellstreak:~$ rm -r projects/budget && ls projects
website

Delete safely: preview, --, and cp -n

Before rm with a wildcard, run ls with the same pattern and read the list. Remember that * skips hidden files, so rm * leaves .env behind, and that ? matches exactly one character (ls beach?.jpg). A file whose name starts with a dash, like -v.txt, looks like a flag: rm -- -v.txt (-- ends the options) or rm ./-v.txt deletes it. cp and mv overwrite silently; cp -n never overwrites and cp -i asks first.

example
learner@shellstreak:~/tidy$ ls -a && rm -- -v.txt && ls
-v.txt
.
..
.env
backup
old-1.log
old-2.log
prices.txt
report.txt
backup
old-1.log
old-2.log
prices.txt
report.txt

Get help: --help, man and less

Most GNU commands print their options with --help, as in head --help or ls --help; pipe it into grep to find one flag, as in grep --help | grep -- -w (the -- makes -w the search text). man grep opens the full manual, in numbered sections (1 commands, 3 C functions, 5 file formats: man 3 printf). Manuals open in less: /word searches, n jumps to the next match, G and g go to the end and start, and q quits. Ctrl-C stops a command that keeps running, like tail -f.

Read files with cat, less, head and tail

cat file prints the whole file. less file lets you scroll through a long one (press q to quit). head -n 5 file shows the first five lines and tail -n 5 file the last five, which is where new entries in a log file end up.

example
learner@shellstreak:~$ head -n 2 projects/budget/budget.csv
month,rent,food,fun
jan,900,310,80

Check yourself

One real exercise from the “Files & folders” unit. No account needed.

Move both recipe files out of Downloads and into Documents, with one command.

What's checked: the files Downloads/recipe-rye.txt, Downloads/recipe-focaccia.txt, Documents/recipe-rye.txt, Documents/recipe-focaccia.txt.

Common mistakes

  • Typing cd.. without a space. It's cd ..: the command, a space, then where to go.

  • Expecting rm to send files to a trash can. In a terminal, deleted files are gone.

  • Forgetting -r when copying or deleting a folder. cp and rm refuse folders without it.

  • Using mkdir a/b when a doesn't exist yet. Add -p to create the parents too.

  • Assuming mv or cp will warn before replacing a file with the same name. They don't, unless you add -i.

Questions

What's the difference between a folder and a directory?+

Nothing: they're two names for the same thing. Terminal commands say directory (that's the d in `pwd` and `mkdir`).

Do these commands work on Mac, Linux and Windows?+

They work in any bash or zsh terminal, which covers macOS, Linux and Windows with WSL or Git Bash. Windows PowerShell has aliases for some of them (`ls`, `cd`, `cat`), but the flags differ.

How do I see hidden files?+

Use `ls -a`. Files and folders whose names start with a dot, like `.bashrc` or `.git`, are hidden from a plain `ls`.

How do I delete a file whose name starts with a dash?+

Put `--` before it, `rm -- -v.txt`, or give a path: `rm ./-v.txt`. Both stop `rm` reading the name as options.

Reading is step one. Now make it stick.

Practise this in a five-minute lesson with instant feedback. No account needed.

Practise it now