Meeting the Unix Shell and Terminal
A Unix command line can look austere at first: a prompt, a blinking cursor, and no obvious buttons. It is simply a precise conversation with programs. Start slowly, work in a directory you own, and read a command before pressing Enter. The first commands in this lesson only display information or create a small practice directory.
The pieces in front of you
| Term | Meaning |
|---|---|
| Terminal | Historically, a keyboard and screen connected to a computer. Today the word also describes the text interface itself. |
| Terminal emulator | A graphical program that imitates a terminal: Terminal on macOS, or apps such as GNOME Terminal, Konsole, xterm, and many others on Unix-like systems. |
| Shell | The command interpreter running inside the terminal. It reads your command, starts programs, and handles quoting, variables, redirection, and pipes. |
| Kernel | The operating system core that manages hardware, memory, filesystems, and processes. You do not type commands directly to it. |
| Command or program | A command is what you ask the shell to run. It might be a shell built-in such as cd, an installed program, or a script. |
sh, bash, zsh, and ksh are shells. Their interactive conveniences differ. The examples below use broadly available, POSIX-style syntax; a command's nonstandard options may still vary on GNU/Linux, BSD, and macOS.
Reading a prompt
alex@laptop:~/practice $
A prompt is configured by your shell. It often shows a user name (alex), a host name (laptop), and the current directory (~/practice). ~ usually means your home directory. The final $ conventionally marks an ordinary user; # often marks an administrative account. Do not type the prompt or the leading $ shown in examples.
Commands, arguments, and options
Most command lines have a command name followed by arguments. Options modify how a command behaves. For example:
$ printf '%s\n' "Hello, Unix"
Hello, Unix
printf is the command. '%s\n' is a format argument and "Hello, Unix" supplies text for it. Options commonly begin with - or --, but their names are not universal. GNU date and BSD/macOS date, for example, accept some different options. Check local documentation with man command or, where supported, command --help.
$ uname
Darwin
$ uname -s
Darwin
uname -s asks for the kernel name. On a Linux system it normally prints Linux; on FreeBSD it normally prints FreeBSD; on macOS it prints Darwin. This identifies the kernel, not necessarily every part of the operating system.
A safe first lab
Use a fresh directory below your home directory, not a system location such as /, /etc, or /usr. The following creates a directory named unix-first-session and enters it. If it already exists, mkdir will report an error rather than overwrite it.
$ cd ~
$ mkdir unix-first-session
$ cd unix-first-session
$ pwd
/home/alex/unix-first-session
Your path will be different. pwd means “print working directory”; it answers “where am I?” cd changes directory and normally prints nothing when successful. If you want to repeat this lab later, choose a new name instead of adding options you do not understand.
Useful first commands
| Command | Purpose | Notes |
|---|---|---|
pwd | Print the current directory. | POSIX and widely available. |
whoami | Print the effective user name. | Useful before doing administrative work. |
uname -s | Print the kernel name. | Use it to notice Linux/BSD/macOS differences. |
date | Print the current date and time. | Formatting options differ across systems. |
printf '%s\n' 'text' | Print predictable text. | Prefer printf in portable scripts; echo has historical option and escape differences. |
$ whoami
alex
$ uname -s
Linux
$ date
Sun Sep 7 10:15:00 UTC 2026
$ printf '%s\n' 'I can read a shell prompt.'
I can read a shell prompt.
The displayed values are examples. Your user name, system name, time zone, and date output will differ.
How the shell knows whether a command worked
When a program finishes, it returns an exit status: 0 conventionally means success, and a nonzero value means some kind of failure or special condition. Immediately after a command, the POSIX shell parameter $? contains that status.
$ pwd
/home/alex/unix-first-session
$ printf '%s\n' "$?"
0
$ cd /this-directory-does-not-exist
sh: cd: can't cd to /this-directory-does-not-exist
$ printf '%s\n' "$?"
2
The exact error wording and nonzero number vary by shell, so scripts should generally test success versus failure rather than expecting a particular number unless the command documents it.
Stopping input and stopping work
- Ctrl-C usually sends an interrupt to the foreground program. It is commonly used to stop a command that is still running. It does not undo work the program already completed.
- Ctrl-D tells the terminal input stream that there is end-of-file when a program is reading input. At an empty interactive prompt it often exits the shell. It does not mean “delete”; do not use it to stop a running command.
These behaviors can be changed by programs or shell settings. If a terminal is busy, wait a moment and use Ctrl-C once; avoid repeatedly sending signals without understanding what is running.
Quoting basics
The shell splits unquoted spaces into separate arguments and treats characters such as *, $, and ; specially. Quotes tell the shell to preserve text.
$ printf '%s\n' one two
one
two
$ printf '%s\n' "one two"
one two
$ printf '%s\n' 'Price: $5; literal text'
Price: $5; literal text
Single quotes preserve the enclosed characters literally. Double quotes preserve spaces but still allow expansions such as $HOME. When a file name or text may contain spaces or special characters, quote it. Do not copy a command from the web until you understand which parts are quoted and which paths it affects.
First-session exercise
- Open a terminal emulator and identify the prompt's current-directory portion.
- Run
pwd,whoami,uname -s, anddate. Record what each reports. - Create and enter a practice directory below your home directory using the safe-lab commands above.
- Run
printf '%s\n' "My current directory is: $PWD". The shell expands$PWDinside double quotes. - Run
printf '%s\n' 'My home is $HOME', then compare it withprintf '%s\n' "My home is $HOME". Notice literal versus expanded text. - Run
cd /this-directory-does-not-exist, read the error, then runprintf '%s\n' "$?". Finally, return to your lab withcd ~/unix-first-session.
A safety habit to keep
The shell will faithfully run a valid command even when the command has a bad target. Avoid commands that delete, overwrite, change ownership, or request administrator privileges until you can explain every word and path. In particular, do not experiment with rm outside disposable practice files, do not add recursive options casually, and do not prefix commands with sudo merely to make an error disappear. A careful pwd, quoted path, and a pause before Enter prevent many mistakes.
dispelled