Command line literacy

Command line literacy

Shell and Terminal

Understand terminals, shells, Bash, Zsh, prompts, command structure, quoting, pipes, redirection, environment variables, PATH, aliases, and startup files.

Audience
Anyone learning commands
Reading time
21 min

Terminal vs shell

A terminal is the interface window or device that displays text and accepts keyboard input. A shell is the program running inside it that interprets commands. Bash and Zsh are shells; GNOME Terminal, Konsole, iTerm2, and the Linux console are terminal interfaces.

This distinction matters because terminal settings and shell behavior are configured in different places.

Bash and Zsh

Bash is the traditional default shell on many Linux systems and the safest assumption for scripts. Zsh is popular for interactive use because of its completion and customization features.

A command that works interactively in Zsh may not be portable to a Bash script. For learning Linux fundamentals, Bash is the common baseline.

Prompt anatomy and command structure

A prompt usually shows context such as username, hostname, current directory, Git branch, or privilege indicator. The prompt is not part of the command; it is a cue from the shell.

Most commands follow a shape: command name, options, arguments, and redirections. Options modify behavior. Arguments tell the command what to act on.

Command anatomy
grep -n "error" /var/log/app.log > errors.txt
# grep = command, -n = option, pattern and file = arguments, > = redirection

Quoting

Quoting controls how the shell treats spaces, variables, and special characters. Single quotes preserve text almost literally. Double quotes allow variable expansion while keeping spaces together.

Many beginner bugs come from unquoted variables or paths with spaces. When in doubt, quote variables as "$name".

Pipes and redirection

A pipe sends the output of one command to the input of another. Redirection sends output to files or reads input from files. These ideas make Unix-style tools composable.

Pipes and redirection diagram
journalctllog stream
grep errorfilter
lesspager
Pipeline example
journalctl -u nginx --since today | grep -i error | less
Redirection example
echo "hello" > message.txt
cat message.txt

Environment variables and PATH

Environment variables are key-value strings inherited by child processes. PATH is an environment variable listing directories the shell searches for commands.

If a command is installed but not found, it may not be in PATH, or your current shell has not loaded the updated environment.

Inspect PATH
echo "$PATH"
which python3

Aliases and shell startup behavior

Aliases are interactive shortcuts. They are convenient but should not be relied on in scripts. Shell startup files such as ~/.bashrc, ~/.bash_profile, ~/.profile, ~/.zshrc, and /etc/profile are loaded in different situations.

Login shells, interactive shells, and non-interactive script shells can read different files. If a setting appears in one terminal but not another, startup file order is a likely cause.

Practical examples

Create a useful alias
alias ll='ls -lah'
Export an editor
export EDITOR=nano
Use command history
history 20