Commands
One Terminal ships with the commands people instinctively type, and they behave like their Unix
counterparts. Typing help lists them all, and help <command> explains one.
ls -la, tree, grep -ri rust, cat "projects/my notes.txt" and history | tail -3.Overview
| Command | What it does |
|---|---|
help | List commands, or show details for one |
ls | List directory contents |
cd | Change directory |
pwd | Print the current directory |
tree | Show the directory structure |
cat | Print files |
grep | Find lines matching a pattern |
head / tail | First / last lines |
wc | Count lines, words and characters |
nl | Number lines |
sort | Sort lines |
uniq | Collapse repeated lines |
echo | Print text |
whoami | Print the username |
neofetch | Show a logo and info |
history | Show and re-run past commands |
sleep | Wait (stop with Ctrl+C) |
clear | Clear the screen |
Turning commands off
Every built-in is on by default. List the ones you don’t want in disabledCommands:
<Terminal disabledCommands={['history', 'neofetch', 'sleep']} />A disabled command answers command not found, and it’s left out of help and tab completion. Keyboard
shortcuts keep working, so Ctrl+L still clears the screen with clear turned off.
To change what a built-in does rather than remove it, add an extra command with the same name: extra commands always take precedence.
Shell syntax
Quotes and escapes
Quotes group words and are removed before the command sees them, just like in bash:
echo "cat" # cat
cat "my file.txt" # reads the file called: my file.txt
cat my\ file.txt # same thing, with a backslash
echo 'single $quotes' # everything inside single quotes is literal
echo "say \"hi\"" # say "hi"An unclosed quote prints zsh: unexpected EOF while looking for matching '"'. Shell errors like this one
and zsh: command not found: foo start with the shell name. It’s zsh by default, and you can change it with the
shellName prop, e.g. shellName="bash".
Pipes
| sends one command’s output into the next one:
history | tail -5
cat skills.txt | grep -i rust | wc -l
grep -r TODO | headCommands that read files (cat, grep, head, tail, wc, nl, sort, uniq) read the piped text when
you don’t give them a file, or when the file is -. Your extra commands
can read it too.
As in bash, each part of a pipeline runs on its own, so cd projects | cat doesn’t change directory, and
clear or history -c only take effect when run by themselves.
Chaining commands
Run several commands on one line:
cd projects && ls # ls only runs if cd worked
grep rust skills.txt || echo no # echo only runs if grep found nothing
clear; neofetch # ; always runs the next command&& runs the next command if the previous one succeeded, || if it failed, and ; either way. Unlike
pipeline stages, chained commands share the session, so cd projects && ls lists projects.
Exit status
Every command finishes with an exit status: 0 for success, anything else for failure. $? holds the last
one:
grep rust skills.txt; echo $? # 0 if something matched, 1 if not
nope; echo $? # 127: command not found| Status | Meaning |
|---|---|
0 | Success |
1 | Failure, e.g. a missing file or grep finding nothing |
2 | Usage or syntax error (and grep errors) |
127 | Command not found |
130 | Interrupted with Ctrl+C |
A pipeline’s status is its last command’s. true and false do nothing except succeed or fail, which is
handy for trying this out. Your own commands can set a status too.
Flags
Flags work the way you’re used to:
ls -la # combined short flags
tree -L 2 # flag with a value...
tree -L2 # ...or attached
head -5 notes.txt # numeric shorthand for -n 5
grep -- -v notes.txt # -- stops option parsing (searches for "-v")Unknown flags print an error, e.g. ls: invalid option -- 'z'.
History expansion
| Syntax | Expands to |
|---|---|
!! | The last command (try sudo !!) |
!n | Command number n from history |
!-n | The command n steps back |
!abc | The most recent command starting with abc |
!$ | The last argument of the last command |
!^ | The first argument of the last command |
^old^new | The last command with old replaced by new |
The expanded command is printed before it runs, like in bash. Nothing inside single quotes is expanded.
Reference
help
help # every command, the keyboard shortcuts, and tips
help grep # usage and flags for one commandYour own commands appear under More commands using their description and usage. You can also
replace help entirely.
ls
ls [-aAlhF1] [path...]| Flag | Effect |
|---|---|
-a | Include hidden entries, plus . and .. |
-A | Include hidden entries |
-l | Long listing (permissions, owner, size, link targets) |
-h | With -l, human-readable sizes (4.0K instead of 4096) |
-1 | One entry per line |
-F | Append / to directories and @ to links |
With several paths, each directory gets a name: header.
cd
cd projects # relative
cd /projects # absolute
cd .. # parent
cd # home (the root)
cd - # back to the previous directorypwd
Prints the absolute path of the current directory, e.g. /projects/web.
tree
tree [-ad] [-L level] [path...]| Flag | Effect |
|---|---|
-a | Include hidden entries |
-d | Directories only |
-L n | Descend at most n levels |
Prints a summary at the end, e.g. 3 directories, 7 files.
cat
cat [-n] [file...]Prints one or more files. Link files become clickable links. -n numbers every line. With no file, it prints
piped input.
grep
grep [-icnvlwrF] pattern [file...]The pattern is a regular expression (if it isn’t valid, it’s matched as plain text). Matches are highlighted.
| Flag | Effect |
|---|---|
-i | Ignore case |
-n | Show line numbers |
-v | Show lines that don’t match |
-c | Count matching lines per file |
-l | Only list files that match |
-w | Match whole words only |
-r | Search directories recursively (the current one by default) |
-F | Treat the pattern as plain text |
grep -i "rust" skills.txt
grep -rn TODO projects
history | grep cdhead / tail
head [-n N] [file...] # first N lines (default 10)
tail [-n N] [file...] # last N lines (default 10)
head -3 notes.txt # shorthandwc
wc [-lwc] [file...]Counts lines (-l), words (-w) and characters (-c). With no flags it shows all three, and with several
files it adds a total.
Output in this terminal never ends with a trailing newline, so wc -l counts lines rather than newline
characters. A three-line file counts as 3 whether or not its content ends with \n, and
cat skills.txt | grep -i rust | wc -l matches what bash would print.
nl
Numbers the non-empty lines of files or piped input.
sort
sort [-rnuf] [file...]| Flag | Effect |
|---|---|
-r | Reverse the order |
-n | Compare numbers, so 10 comes after 9 |
-u | Drop duplicate lines |
-f | Ignore case |
uniq
uniq [-cdui] [file]Collapses repeated neighbouring lines, so sort first: sort words.txt | uniq -c.
| Flag | Effect |
|---|---|
-c | Prefix each line with how often it repeats |
-d | Only show repeated lines |
-u | Only show lines that don’t repeat |
-i | Ignore case |
echo
Prints its arguments separated by spaces. Quotes are removed first, so echo "a b" keeps the spaces.
whoami
Prints the username prop (guest by default).
neofetch
Shows a logo with system info next to it, or your own info. See Neofetch.
history
history # every command, numbered
history 5 # the last 5
history -c # clear the historyUse the numbers with !n. The history lasts for the session and resets on reload.
sleep
sleep 2 # seconds
sleep 1.5 # decimals
sleep 2m # also s, m and h suffixesThe prompt disappears while it runs. Press Ctrl+C to stop it early.
clear
Clears the screen and the welcome message. Ctrl+L does the same but keeps what you are typing.
Any built-in can be replaced: define an extra command with the same name (for example ls or whoami) and
yours runs instead. See Extra Commands.