Shell basics and navigation
Paths, the commands used every day, and how to read a command line rather than memorizing flags.
Paths
| Symbol | Meaning |
|---|---|
. | Current directory |
.. | Parent directory |
~ | Your home directory |
/ | Root of the filesystem (also a separator) |
- | Previous directory (with cd -) |
pwd # print working directory
ls -la # long list, including hidden files
cd /var/log
cd ~/projects
cd -
# tab completion prevents typos
cat /etc/ho<TAB>π‘
Anything starting with
/ is absolute; anything else resolves relative to where you are. That single rule explains most 'file not found' surprises.The daily dozen
| Command | Does |
|---|---|
ls | List directory contents |
cd | Change directory |
cp / mv / rm | Copy / move / delete |
mkdir / touch | Create directory / empty file |
cat / less | Dump / page through a file |
grep | Search text |
head / tail | First / last lines |
man / --help | Documentation |
mkdir -p src/components # -p creates parents, no error if exists
touch notes.txt
cp file.txt backup.txt
cp -r src/ src.bak/
mv old.txt new.txt
rm -i important.txt # ask before deletingβ οΈ
rm -rf deletes recursively without asking and there is no recycle bin. Pause before running it, especially with globs or variables: rm -rf $DIR/* with an empty DIR is a classic disaster.Wildcards and quoting
ls *.js # zero or more characters
ls file?.txt # exactly one character
cp src/*.js dist/
grep 'error 500' app.log # quote anything with spaces
grep "$PATTERN" app.log # expand the variable
grep '$100' prices.txt # single quotes keep the $ literalThe shell expands globs before the command runs, and expands variables inside double quotes but not single quotes. Get those two facts right and most quoting bugs disappear.
Saving keystrokes
history | grep ssh
!! # repeat last command
sudo !! # repeat it with sudo
Ctrl-R # reverse search through history
alias ll='ls -la'FAQ
'command not found' β but it is installed?
It is not on your
PATH. Use the full path, or add its directory to the PATH in your shell profile.Permission denied?
The file lacks execute permission (
chmod +x), or the operation needs sudo. Prefer adding your user to a group over blanket sudo.Related
Files and permissions Working with text
Last refreshed 2026-09-17.