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
Add to a file
> replaces a file. >> adds to the end of it, and creates the file if it
does not exist:
home://notes> echo first >> log.txt
home://notes> echo second >> log.txt
home://notes> cat log.txt
first
second
>> never removes what is already there. When two shells add to the same file
at the same time, neither overwrites the other’s text.
Edit the line
-
Press Tab to complete a command or file name; see Complete names.
-
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
Complete names
Tab completes the word before the cursor. Add two more files to notes:
home://notes> echo draft > report.txt
home://notes> cp bin://echo.pxe say.pxe
-
Type the start of a file name and press Tab. The shell finishes the name and adds a space:
home://notes> cat rep<Tab> home://notes> cat report.txt -
The first word of a line completes to a command:
home://notes> ec<Tab> home://notes> echo -
A program in the current directory needs
./, and completes after it:home://notes> ./sa<Tab> home://notes> ./say.pxe hello hello -
Paths into other directories and roots complete the same way. A directory ends with
/, so the next Tab goes one level deeper:home://notes> ls ../notes/sa<Tab> home://notes> ls ../notes/say.pxe home://notes> ls system://co<Tab> home://notes> ls system://config/ home://notes> bin://ech<Tab> home://notes> bin://echo.pxeStarting a root name offers the root:
ls homcompletes tols home://. -
When several names fit, the first Tab adds what they share. If that adds nothing, press Tab again to list them under the line:
home://notes> ./<Tab><Tab> ./a.txt ./b.txt ./log.txt ./report.txt ./say.pxeA short start can match files and roots together:
cat alistsa.txtand any root that starts witha, such asacpi://. Type another letter to narrow it.
Tab never starts a network request, so http:// and https:// words are not
completed.
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.
Make shortcuts
An alias is a short name for a command with fixed arguments. Aliases live in
home://.config/shell/startup.lua. The shell reads that file once, when it
starts.
-
Create the file. This one makes
llmeanls -l:home://> mkdir .config home://> mkdir .config/shell home://> echo 'return { aliases = { ll = { "ls", "-l" } } }' > .config/shell/startup.luaEach alias is a name and a list of strings: the command, then its arguments. To change the file later, open it with
vi(vi .config/shell/startup.lua). -
Start a new shell. On an installed system, run
reboot. Then use the alias, and askwhichwhat it stands for:home://> ll notes file 4 a.txt file 4 b.txt file 13 log.txt ... home://> which ll ll: alias 'ls' '-l'Whatever you type after the alias is added to its arguments. Tab offers alias names with the commands.
-
To run the real command instead of the alias, quote the name (
'ls') or write\ls.
The same file can also set variables for the shell (variables) and for the
programs it starts (exported). Values in it are plain text: the shell never
runs the file as code. If the file has a mistake, the shell says what is wrong
when it starts and ignores the whole file:
shell: home://.config/shell/startup.lua: an alias must be a nonempty string array; none applied
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