Shell commands¶
This page is for macOS and Linux users who have not used a command line before. It explains the small set of Shell commands used elsewhere in this guide. macOS normally uses zsh zsh and Ubuntu normally uses bash bash; the commands on this page work in both.
You do not need to memorise them. Keep this page open, copy one command at a time, and check what happened before continuing.
Commands act immediately
A terminal does not normally put deleted files in the Trash or ask you to
confirm every change. Do not add sudo, -f, or -r to a command unless
the instructions explicitly require it and you understand the target.
Understand the prompt¶
When the terminal is waiting for a command, it displays a prompt similar to:
The prompt provides context:
(.venv)means the project's Python virtual environment is active.mark@macbookidentifies the user and computer.my-reportis usually the current directory.%is a common macOS prompt marker; Ubuntu often uses$instead.
Do not type the prompt itself. If an instruction shows:
type only:
Press Enter to run it. Most successful shell commands print little or
nothing; the next prompt means the command has finished.
Understand a command¶
A command normally consists of a program name followed by options and arguments:
- The command selects the program to run.
- An option changes its behaviour and commonly starts with
-or--. - An argument tells it what to work on, such as a file or directory.
Words such as PROJECT-DIRECTORY, FILE, and USERNAME in this guide are
placeholders. Replace them with your own value; do not type the capitalised
placeholder or its surrounding angle or square brackets.
Shell commands are case-sensitive. Docs, docs, and DOCS can be three
different names. Spaces also separate arguments, so put a path containing a
space inside quotes:
Use straight quotes copied from a code block, not typographic “smart quotes”.
Understand paths¶
A path path tells a command where a file or directory is. These short forms are used throughout the guide:
1. Common path forms
| Path | Meaning |
|---|---|
/ |
The top of the filesystem. |
~ |
Your home directory, such as /Users/mark or /home/mark. |
. |
The current directory. |
.. |
The current directory's parent. |
docs/index.md |
A path relative to the current directory. |
/home/mark/report/docs/index.md |
An absolute path starting at /. |
The forward slash / separates directories on both macOS and Linux.
Find and change the current directory¶
The current directory is the directory a command works from unless you give
it another path. Before running a project command, confirm that you are in the
project directory—the one containing a Zensical configuration such as
zensical.toml, or a legacy mkdocs.yml file that Zensical reads directly.
A safe way to start a session is:
Read the output from pwd and ls. Continue only when you can see the expected
configuration file.
Use Tab completion
Type the first few characters of a file or directory, then press Tab.
The shell completes an unambiguous name, reducing typing and spelling
errors. Press Tab twice to see possible matches.
Activate the project environment¶
Prodockit and Zensical are installed inside the project's .venv directory.
After changing to the project directory, activate it with:
The prompt gains a (.venv) prefix. Activation applies only to this terminal
window; repeat it after opening a new one.
Useful checks are:
command -v prints the program that the shell will run. For the project Python
and prodockit commands, the path should normally pass through the project's
.venv directory.
Run deactivate when you deliberately want to leave the environment. Closing
the terminal also ends it.
Create, copy, move, and remove files¶
Prefer your editor, Finder on macOS, or Files on Ubuntu for ordinary file management. When a guide asks you to use the shell, these commands are the common ones:
3. File and directory commands
| Command | What it does |
|---|---|
mkdir NAME |
Creates a directory called NAME. |
mkdir -p PATH |
Creates a path and any missing parent directories. |
cp SOURCE DESTINATION |
Copies one file. |
cp -R SOURCE DESTINATION |
Copies a directory and its contents. |
mv SOURCE DESTINATION |
Moves or renames a file or directory. |
rm -i FILE |
Asks before permanently removing one file. |
rmdir DIRECTORY |
Removes an empty directory. |
Before copying, moving, or removing anything, use pwd and ls to verify the
source and destination. Put paths containing spaces in quotes.
Avoid recursive forced deletion
rm -rf removes a directory tree without confirmation. A typing mistake
can delete an entire project or home directory. It is intentionally not
part of the normal workflow in this guide; use Finder or Files when you
need a recoverable deletion.
Read a text file¶
4. Commands for reading files
| Command | What it does |
|---|---|
cat FILE |
Prints a short file in full. |
less FILE |
Opens a longer file for scrolling; press q to leave. |
head -n 20 FILE |
Prints its first 20 lines. |
tail -n 20 FILE |
Prints its last 20 lines. |
nl -ba FILE |
Prints it with line numbers, including blank lines. |
These commands do not edit the file. For example:
Inside less, use the arrow keys or Page Up/Page Down to move, type /word to
search, press n for the next match, and press q to return to the prompt.
Edit a text file¶
Use your normal editor for document work. If an installation instruction asks
you to change a small configuration file directly in the terminal, nano is a
beginner-friendly editor available on macOS and Ubuntu:
Replace FILE with the path from the instruction. Inside nano:
- Type and use the arrow keys as you would in a simple text editor.
- Press
Ctrl+O, thenEnter, to save the file. - Press
Ctrl+Xto leave. - If it asks whether to save modified content, press
Yto save orNto discard it, then follow the filename prompt.
The ^ shown in nano's shortcut bar means Ctrl; ^X therefore means
Ctrl+X. Do not use sudo nano unless the relevant platform instructions
explicitly include sudo.
Find files and text¶
Use find to locate a file and grep grep to locate text
inside files:
find .starts in the current directory.*.mdmeans every name ending in.md; quotes stop the shell expanding it beforefindreceives it.grep -nincludes line numbers.grep -Rsearches through subdirectories.
A pipe, written |, sends the output of one command into another. This example
shows only Markdown files whose paths contain install:
Control a running command¶
Some commands, including zensical serve, deliberately keep running. The
terminal is not stuck merely because no new prompt appears.
5. Useful terminal keys
| Key | What it does |
|---|---|
Ctrl+C |
Stops the command currently running in the terminal. |
Ctrl+L |
Clears the visible screen without deleting command history. |
Up / Down |
Moves through commands previously entered. |
Left / Right |
Edits the current command before it is run. |
Tab |
Completes a command or path where possible. |
If the prompt changes to quote>, dquote>, or >, the shell is usually
waiting for a closing quote or bracket. Press Ctrl+C to abandon the incomplete
command, then enter it again carefully.
Use administrator access carefully¶
sudo COMMAND runs a command with administrator privileges. Use it only when a
platform-specific instruction in this guide includes it—for example, Ubuntu's
apt package installation. Do not add it merely because another command
reported an error.
When sudo asks for your password, the terminal shows no characters, dots, or
asterisks while you type. That is normal. Type the password and press Enter.
Warning
Do not run sudo pip, sudo prodockit, or sudo zensical. Python packages
belong in the activated virtual environment and do not need administrator
access.
Understand common errors¶
command not found¶
Check the spelling. If the missing command is prodockit, zensical, or
python, change to the project directory and activate .venv. If an installer
has just changed PATH, open a new terminal and activate .venv again.
No such file or directory¶
Run pwd and ls to check your location and the exact spelling and case of the
path. Quote a path containing spaces.
Permission denied¶
First check that the path is correct and belongs to you. Do not immediately
retry with sudo; the command may be targeting a system file or the wrong
directory. Follow the relevant installation instructions when administrator
access is genuinely required.
A command prints nothing¶
Many commands report errors but say nothing on success. Run a read-only check
such as ls, git status, or the --version command given by the instructions
to confirm the expected result.
Where to go next¶
Return to Start editing and use this page whenever a command or path is unfamiliar. Continue to Document appearance and structure when you are comfortable previewing, building, and saving routine document changes.