Shell basics
The shell reads one command per line and runs it. Its prompt shows the current
directory, so home://notes> means you are in the notes directory of
home://. The examples below start in an empty home.
Run commands
-
echoprints its arguments:home://> echo hello hello -
>writes a command’s output to a file.catprints a file:home://> echo hello > note.txt home://> cat note.txt hello -
Quote an argument that contains spaces or special characters, with single or double quotes:
home://> mkdir 'two words'
Directories and files
-
mkdirmakes a directory,cdenters it andlslists it.cd ..goes up:home://> mkdir notes home://> cd notes home://notes> echo one > a.txt home://notes> echo two > b.txt home://notes> ls a.txt b.txt home://notes> cd .. home://> -
cpcopies,mvmoves or renames andrmremoves:home://notes> cp a.txt c.txt home://notes> mv c.txt d.txt home://notes> rm d.txt home://notes> ls a.txt b.txtrm -rremoves a directory and everything in it.
Wildcards
An unquoted * stands for any run of characters in a file name. The shell
replaces the word with the matching names, in sorted order, before it runs the
command:
home://notes> echo *.txt
a.txt b.txt
home://notes> cat a.txt b.txt
one
two
-
*works only in the last part of a path:notes/*.txtis fine, and*/a.txtis refused:shell: Wildcards are supported only in the last path component: */a.txt -
A name that starts with
.matches only a pattern that starts with., so*does not match.history. -
If nothing matches, the command does not run:
home://notes> echo *.md shell: No match: *.md (quote it to pass it literally) -
Quote the
*to pass it through unchanged:home://notes> echo '*.txt' *.txt
Edit the line
-
Press Tab to complete a name. With
cat atyped, Tab givescat a.txt. -
Press Ctrl+C to throw away the line you are typing.
-
Press Ctrl+C while a command runs to stop it:
home://> sleep 30 shell: sleep: Process terminated
History
The shell remembers what you typed, and keeps it after a reboot.
-
Press Up to bring back an earlier line, Down to go forward. Edit the line if you like, then press Enter to run it.
-
Press Ctrl+R and type part of a line to search backwards:
(reverse-i-search)'mv': mv c.txt d.txtPress Ctrl+R again for an older match, Enter to run the line, or Esc to keep it for editing. Ctrl+G cancels the search.
-
Start a line with a space to keep it out of the saved history.
Clear and reset
-
clearempties the screen:home://notes> clear -
resetputs the terminal back to normal if a program left it in a strange state, such as a hidden cursor or leftover colours. It does not erase the screen:home://notes> reset