Skip to Content
DocsCommands

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.

Try ls -la, tree, grep -ri rust, cat "projects/my notes.txt" and history | tail -3.

Overview

CommandWhat it does
helpList commands, or show details for one
lsList directory contents
cdChange directory
pwdPrint the current directory
treeShow the directory structure
catPrint files
grepFind lines matching a pattern
head / tailFirst / last lines
wcCount lines, words and characters
nlNumber lines
sortSort lines
uniqCollapse repeated lines
echoPrint text
whoamiPrint the username
neofetchShow a logo and info
historyShow and re-run past commands
sleepWait (stop with Ctrl+C)
clearClear 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 | head

Commands 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
StatusMeaning
0Success
1Failure, e.g. a missing file or grep finding nothing
2Usage or syntax error (and grep errors)
127Command not found
130Interrupted 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

SyntaxExpands to
!!The last command (try sudo !!)
!nCommand number n from history
!-nThe command n steps back
!abcThe most recent command starting with abc
!$The last argument of the last command
!^The first argument of the last command
^old^newThe 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 command

Your own commands appear under More commands using their description and usage. You can also replace help entirely.

ls

ls [-aAlhF1] [path...]
FlagEffect
-aInclude hidden entries, plus . and ..
-AInclude hidden entries
-lLong listing (permissions, owner, size, link targets)
-hWith -l, human-readable sizes (4.0K instead of 4096)
-1One entry per line
-FAppend / 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 directory

pwd

Prints the absolute path of the current directory, e.g. /projects/web.

tree

tree [-ad] [-L level] [path...]
FlagEffect
-aInclude hidden entries
-dDirectories only
-L nDescend 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.

FlagEffect
-iIgnore case
-nShow line numbers
-vShow lines that don’t match
-cCount matching lines per file
-lOnly list files that match
-wMatch whole words only
-rSearch directories recursively (the current one by default)
-FTreat the pattern as plain text
grep -i "rust" skills.txt grep -rn TODO projects history | grep cd

head / tail

head [-n N] [file...] # first N lines (default 10) tail [-n N] [file...] # last N lines (default 10) head -3 notes.txt # shorthand

wc

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...]
FlagEffect
-rReverse the order
-nCompare numbers, so 10 comes after 9
-uDrop duplicate lines
-fIgnore case

uniq

uniq [-cdui] [file]

Collapses repeated neighbouring lines, so sort first: sort words.txt | uniq -c.

FlagEffect
-cPrefix each line with how often it repeats
-dOnly show repeated lines
-uOnly show lines that don’t repeat
-iIgnore 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 history

Use 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 suffixes

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

Last updated on