Getting Comfortable in the Linux Terminal

Short answer

Open a terminal with Ctrl+Alt+T (Ubuntu, Mint) or by searching "Terminal" in the app menu. Copy and paste with Ctrl+Shift+C / Ctrl+Shift+V, stop a command with Ctrl+C, and complete names with Tab. Start here:

pwd
ls -la
man ls

Terminal, shell and console: what's what

  • Terminal emulator: the window. It handles fonts, tabs, colours and copy-paste. Examples: Ptyxis (default on current GNOME-based Fedora and Ubuntu releases), GNOME Terminal, Konsole (KDE Plasma), xfce4-terminal, and cross-desktop options like Alacritty, kitty and WezTerm.
  • Shell: the program running inside the window that reads what you type. bash is the default on almost every distribution. Kali and macOS use zsh; fish is a popular friendly alternative.
  • Console / TTY: text-only sessions without a desktop, reached with Ctrl+Alt+F3 to F6 on most distributions. Useful when the desktop is frozen or won't start; Ctrl+Alt+F1 or F2 usually returns to the graphical session.

Check which shell you're using and which ones are installed:

echo "$SHELL"
ps -p $$
cat /etc/shells

Change your login shell with chsh -s /usr/bin/zsh (install the shell first), then log out and back in. Scripts are unaffected: they use whatever their shebang line says. See the bash scripting tutorial when you're ready to write them.

Reading the prompt and moving around

A typical prompt looks like this:

alex@laptop:~/projects$

That's user alex on host laptop, in ~/projects (~ is your home directory, /home/alex). A $ means a normal user; # means you're root, so be careful.

pwd                 # where am I?
ls                  # list files
ls -la              # long format, including hidden dotfiles
cd /etc             # absolute path: starts at /
cd projects         # relative path: from where you are
cd ..               # up one level
cd -                # back to the previous directory
cd                  # home

Wildcards and tab completion

The shell expands wildcards before the command runs, so they work with any program:

ls *.txt            # every .txt file in this directory
ls report-202?.pdf  # ? matches exactly one character
cp ~/Downloads/*.{jpg,png} ~/Pictures/   # brace expansion: both extensions
echo ~/Documents/*  # see what a pattern expands to before using it

Run echo with a pattern first whenever you're about to delete or move files with one. Tab completion does more than file names: on most distributions bash completes command options, package names for apt install and dnf install, systemd unit names for systemctl and hosts from ~/.ssh/config. If it doesn't, install the bash-completion package.

Names with spaces need quotes or a backslash: cd "My Documents" or cd My\ Documents. Tab completion inserts the escaping for you. For the next set of commands (copying, moving, searching, disk usage), see essential Linux commands.

Keyboard shortcuts that save the most time

KeysWhat it does
TabComplete a command, file or option; press twice to list choices
Ctrl+CInterrupt (stop) the running command
Ctrl+DEnd of input; on an empty prompt, closes the shell
Ctrl+ZSuspend the running command (resume with fg)
Ctrl+LClear the screen
Ctrl+RSearch command history backwards; press again for older matches
Up / DownPrevious / next command
Ctrl+A / Ctrl+EJump to start / end of the line
Alt+B / Alt+FMove back / forward one word
Ctrl+WDelete the word before the cursor
Ctrl+U / Ctrl+KDelete to start / end of the line
Ctrl+Shift+C / Ctrl+Shift+VCopy / paste in most terminal emulators
Ctrl+Shift+TNew tab (GNOME-style terminals and Konsole)
Alt+.Insert the last argument of the previous command

If the terminal suddenly stops responding to typing, you may have pressed Ctrl+S, which pauses output on many terminals. Press Ctrl+Q to resume.

History and repeating commands

history | tail -20     # recent commands with numbers
!42                    # run command number 42
!!                     # repeat the last command
sudo !!                # repeat the last command with sudo
!ssh                   # rerun the most recent command starting with "ssh"

Bash saves history to ~/.bash_history when a shell exits. To keep more and share it between open tabs, add this to ~/.bashrc:

HISTSIZE=10000
HISTFILESIZE=20000
HISTCONTROL=ignoreboth     # skip duplicates and lines starting with a space
shopt -s histappend
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"

Starting a command with a space keeps it out of history with ignoreboth, which is handy when a command contains a token or password.

Pipes, redirection and combining commands

Most Linux tools do one thing and are joined with pipes. The output of one command becomes the input of the next:

ps aux | grep firefox            # find a process
journalctl -b | less             # scroll through this boot's log
du -sh ~/* | sort -h | tail      # biggest items in your home
ls /etc > etc-list.txt           # save output to a file
ls /nope 2> errors.txt           # save errors
make && sudo make install        # second runs only if the first succeeds
cd /tmp || exit                  # second runs only if the first fails

Inside less and man: /word searches, n jumps to the next match, q quits. For search tools, the grep cheat sheet is a good next step.

sudo, root and permissions

Normal users can't change system files. Prefix a command with sudo to run it as root; you type your own password, and on many systems nothing is shown while you type.

sudo apt update
sudo -i            # root shell (exit with exit or Ctrl+D)
sudo -l            # what am I allowed to run?

Ubuntu 26.04 uses sudo-rs, a Rust reimplementation, as its default sudo; everyday usage is the same. If you get "is not in the sudoers file", see user is not in the sudoers file. If a file says "Permission denied", read Linux file permissions before reaching for sudo, and never fix it with chmod 777.

Pasting commands from the internet

Read commands before you run them, especially ones with sudo, rm -rf, dd or curl ... | sudo bash. For install scripts, download the file first, read it, then run it. Some web pages hide extra text in what gets copied, so pasting into a text editor first is a reasonable habit.

Getting help without leaving the terminal

man tar               # full manual page
man -k partition      # search manual page descriptions
tar --help            # short usage summary
help cd               # help for bash built-ins
type ll               # is it an alias, function, built-in or file?
which python3         # where is the program?

Install tldr (package tldr or tealdeer) for short example-based summaries. The cheat sheets on this site cover the tools you'll meet first: find, tar, systemctl and journalctl. If a command isn't found at all, see bash: command not found.

Jobs, long-running commands and sessions

long_command &        # run in the background
jobs                  # list background jobs
fg %1                 # bring job 1 back to the foreground
bg                    # continue a suspended job in the background
kill %1               # end job 1
nohup long_command > out.log 2>&1 &   # keep running after you close the terminal

For anything that runs for a long time over SSH, use tmux instead: the session survives disconnects and you can reattach later. The tmux cheat sheet has the key bindings.

Making the terminal yours

Bash reads ~/.bashrc for every interactive shell. Add aliases and settings there, then run source ~/.bashrc or open a new tab.

# ~/.bashrc additions
alias ll='ls -lah'
alias update='sudo apt update && sudo apt upgrade'   # adjust for dnf/pacman/zypper
export EDITOR=nano
# add your own scripts to PATH
export PATH="$HOME/.local/bin:$PATH"
  • Fonts and colours live in the terminal emulator's preferences, not the shell.
  • zsh reads ~/.zshrc; fish reads ~/.config/fish/config.fish and uses its own syntax for variables and functions.
  • Prompt themes like Starship work across bash, zsh and fish; install from your distribution's repositories where packaged rather than piping an installer into the shell.

Editing files from the terminal

You'll regularly edit configuration files such as ~/.bashrc or files in /etc. nano is installed almost everywhere and shows its shortcuts at the bottom (Ctrl+O saves, Ctrl+X exits). vim is more powerful but modal; if you end up in it by accident, press Esc, type :q! and Enter to leave without saving. The vim cheat sheet covers the rest. For system files, use sudoedit /etc/file, which edits a copy as your user and writes it back with root rights, instead of running the whole editor as root.

Install alternative shells and terminals with your package manager: sudo apt install zsh, sudo dnf install zsh, sudo pacman -S zsh or sudo zypper install zsh.

Frequently asked questions

How do I copy and paste in the Linux terminal?

Use Ctrl+Shift+C and Ctrl+Shift+V; plain Ctrl+C sends an interrupt to the running program. Selecting text with the mouse and middle-clicking also pastes on most desktops.

Why doesn't anything appear when I type my sudo password?

Many systems don't echo the password at all, not even as asterisks, to avoid revealing its length. Type it and press Enter. Whether you see feedback depends on the distribution's sudo configuration.

What is the difference between a terminal and a shell?

The terminal (emulator) is the window that draws text and handles the keyboard. The shell, usually bash or zsh, is the program inside it that reads your commands and runs them.

How do I stop a command that is running?

Press Ctrl+C to interrupt it. If a program ignores that, Ctrl+Z suspends it and kill %1 ends it; as a last resort, close the terminal tab.

Spotted a mistake or a command that no longer works? Send a correction — pages are re-checked when reports come in.