Shell basics and navigation

Paths, the commands used every day, and how to read a command line rather than memorizing flags.

Paths

SymbolMeaning
.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

CommandDoes
lsList directory contents
cdChange directory
cp / mv / rmCopy / move / delete
mkdir / touchCreate directory / empty file
cat / lessDump / page through a file
grepSearch text
head / tailFirst / last lines
man / --helpDocumentation
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 $ literal

The 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.

Files and permissions Working with text

Last refreshed 2026-09-17.