knowledge

Overview

Linux shells provide the command-line interface between the user and the operating system. Different shell types offer varying features, scripting capabilities, and user experiences. The shell prompt is configurable and communicates context (user, host, directory). Shell scripting allows automation of repetitive tasks through executable script files.


Terminology

TermDefinition
ShellCommand-line interface for interacting with the OS
PS1Environment variable that controls how the shell prompt is displayed
ShebangFirst line of a script declaring which interpreter to use (e.g., #!/bin/bash)
VariableNamed storage location holding a value within a script or session
LoopProgramming construct that repeats a block of code
Conditional StatementLogic that executes code only when a condition is met
chshCommand to change a user’s default shell
Man PageBuilt-in documentation for commands accessed via man

Core Concepts

Shell Types

/etc/shells contains all shells installed on the system.

  • Switch to a different shell temporarily by typing its name: zsh
  • Permanently change default shell: chsh -s /usr/bin/zsh
ShellDescription
bashBourne Again Shell — default on most Linux distros
zshExtended bash with better completion and plugins
fishUser-friendly shell with syntax highlighting
shPOSIX-compliant minimal shell
kshKorn shell — common on enterprise UNIX systems

Prompt Description

The shell prompt communicates context. Root uses #; regular users use $. The home directory is represented by ~.

The PS1 variable in .bashrc controls prompt appearance. Common special characters:

CharacterMeaning
\uCurrent username
\hHostname (short)
\wFull current working directory
\WCurrent directory name only
\$# if root, $ otherwise
\tCurrent time (HH:MM:SS)
\dCurrent date

Example: PS1="\u@\h:\w\$ " → displays user@host:/current/dir$

Edit .bashrc to make prompt changes persistent. Resources:


Getting Help

CommandDescription
man <tool>Full manual page for a command — comprehensive reference
<tool> --helpQuick help output — faster than man for common flags
<tool> -hShort help — supported by some tools as an alias for --help
apropos <keyword>Search all man page descriptions for a keyword

apropos is useful when you know what you want to do but not which command to use. Resource: https://explainshell.com/ — paste any command to get a breakdown of every component.


Keyboard Shortcuts

Cursor Movement

ShortcutAction
[CTRL] + AMove cursor to beginning of line
[CTRL] + EMove cursor to end of line
[CTRL] + ← / [CTRL] + →Jump backward/forward one word

Editing the Current Line

ShortcutAction
[CTRL] + UErase from cursor to beginning of line
[CTRL] + KErase from cursor to end of line
[CTRL] + WErase the word before the cursor
[CTRL] + YPaste the last erased text

Process Control

ShortcutAction
[CTRL] + CTerminate current process (sends SIGINT)
[CTRL] + ZSuspend current process (sends SIGTSTP)
[CTRL] + DClose STDIN / send EOF (End-of-Transmission)
ShortcutAction
[CTRL] + LClear the terminal (same as clear)
[CTRL] + RSearch command history interactively
[↑] / [↓]Navigate command history
[TAB]Auto-complete command, file, or directory name
[ALT] + [TAB]Switch between open applications

Zoom

ShortcutAction
[CTRL] + [+]Zoom in
[CTRL] + [-]Zoom out

Shell Scripting

Full coverage of bash scripting — variables, loops, conditionals, functions, operators, and debugging — is documented in Shell Scripting.



References / Images