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

TermMeaning
TerminalHistorically, a keyboard and screen connected to a computer. Today the word also describes the text interface itself.
Terminal emulatorA graphical program that imitates a terminal: Terminal on macOS, or apps such as GNOME Terminal, Konsole, xterm, and many others on Unix-like systems.
ShellThe command interpreter running inside the terminal. It reads your command, starts programs, and handles quoting, variables, redirection, and pipes.
KernelThe operating system core that manages hardware, memory, filesystems, and processes. You do not type commands directly to it.
Command or programA 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

CommandPurposeNotes
pwdPrint the current directory.POSIX and widely available.
whoamiPrint the effective user name.Useful before doing administrative work.
uname -sPrint the kernel name.Use it to notice Linux/BSD/macOS differences.
datePrint 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

  1. Open a terminal emulator and identify the prompt's current-directory portion.
  2. Run pwd, whoami, uname -s, and date. Record what each reports.
  3. Create and enter a practice directory below your home directory using the safe-lab commands above.
  4. Run printf '%s\n' "My current directory is: $PWD". The shell expands $PWD inside double quotes.
  5. Run printf '%s\n' 'My home is $HOME', then compare it with printf '%s\n' "My home is $HOME". Notice literal versus expanded text.
  6. Run cd /this-directory-does-not-exist, read the error, then run printf '%s\n' "$?". Finally, return to your lab with cd ~/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.