How to Open and Use the Linux Terminal
The terminal is a window running a shell, usually bash (some distros and many users pick zsh or fish). You type a command, the shell runs it and prints the result. Everything you can click in a Linux desktop can also be done here, and on a server it is the only interface you get.
Open a terminal on a desktop
- Press
Ctrl+Alt+T. This works on Ubuntu, GNOME, KDE Plasma, Xfce and most other desktops. - Open the application launcher (the
Superkey on GNOME) and type "terminal". - In the file manager, right-click inside a folder and choose "Open in Terminal" to start in that folder.
Alt+F2opens a run dialog on GNOME and KDE where you can type the terminal's name.
The app itself differs by desktop: Ptyxis on Ubuntu 25.10 and later and on Fedora Workstation 41 and later, GNOME Terminal on older GNOME releases, Konsole on KDE Plasma, xfce4-terminal on Xfce. They all run the same shell.
Without a working desktop, Ctrl+Alt+F3 to Ctrl+Alt+F6 switch to text consoles where you can log in. Ctrl+Alt+F1 or F2 (depending on the distro) returns to the graphical session.
Open a terminal on a remote server
ssh user@203.0.113.10
ssh -i ~/.ssh/my-key.pem ubuntu@203.0.113.10
On AWS you can skip open SSH ports and key distribution: aws ssm start-session --target i-0123456789abcdef0 opens a shell through Session Manager (it needs the Session Manager plugin locally and the SSM agent plus an instance role on the server), and aws ec2-instance-connect ssh --instance-id i-0123456789abcdef0 connects with a short-lived key.
On Windows, wsl --install gives you a real Ubuntu terminal. The macOS Terminal app is not Linux, but most commands in this post work the same way there.
Read the prompt
user@web-01:~/projects$
That is the user name, the host name, the current directory (~ is your home directory) and the prompt symbol. $ means a regular user and # means root, a reminder to be careful.
A command has the form command -options arguments, for example ls -lh /var/log. Short options can be combined (-l -h is the same as -lh), and most have a long form like --human-readable.
Move around and manage files
pwd # print the current directory
ls -lah # list everything, including hidden files, readable sizes
cd /var/log # go to an absolute path
cd .. # one level up
cd - # back to the previous directory
cd # home directory
mkdir -p my-app/src # create directories
cp -r src backup # copy a directory
mv old.txt new.txt # move or rename
rm file.txt # delete a file
rm -r old-dir # delete a directory
rm has no trash bin. Deleted means deleted, so read the command twice before running rm -r, especially with sudo or wildcards.
More detail on each task: creating files and directories, moving files, viewing files, finding files, permissions.
Get help
man ls # full manual; / to search, q to quit
ls --help # short summary of options
help cd # help for shell built-ins like cd
type ls # alias, built-in or file?
man -k compress # search manual pages by keyword
Keyboard shortcuts
Tab: complete commands and paths. Press it twice to see all options.UpandDown: walk through command history.Ctrl+Rsearches it.Ctrl+C: stop the running command.Ctrl+D: end input, or log out of an empty prompt.Ctrl+L: clear the screen.Ctrl+AandCtrl+E: jump to the start and end of the line.Ctrl+WandCtrl+U: delete the previous word, or everything before the cursor.Ctrl+Z: suspend a program,fgbrings it back.Ctrl+Shift+CandCtrl+Shift+V: copy and paste in most terminal apps. PlainCtrl+Cstops a command instead of copying.sudo !!: repeat the last command with sudo.
Pipes and redirection
ls -l > files.txt # write output to a file (overwrite)
echo done >> log.txt # append
command 2> errors.txt # only error output
command > all.log 2>&1 # output and errors to one file
du -sh * | sort -h | tail -5 # five biggest items here
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head # top client IPs
mkdir build && cd build # second command only if the first succeeded
make || echo "build failed" # second command only if the first failed
The pipe | sends one command's output into the next command's input. Small tools chained this way (grep, sort, uniq, awk, head) answer most ad hoc questions about logs and files. See How to use grep for the most useful one.
sudo and root
Commands that change the system need root privileges:
sudo apt update && sudo apt upgrade # Debian, Ubuntu
sudo dnf upgrade # Fedora, RHEL 8 and later
sudo asks for your own password and shows nothing while you type. sudo -i opens a root shell; use it sparingly and exit as soon as you are done.
Check the system
df -h # disk space per filesystem
free -h # memory
uptime # load average
top # live processes (htop is nicer if installed)
ss -tulpn # listening ports
journalctl -f # follow the system log
Make it yours: aliases, variables, prompt
Shell settings live in ~/.bashrc:
alias ll='ls -lah'
alias k='kubectl'
export EDITOR=vim
PS1='\u@\h:\w\$ '
Reload with source ~/.bashrc or open a new terminal. In PS1, \u is the user, \h the host and \w the current directory.
Keep sessions alive with tmux
A command started over SSH dies when the connection drops. tmux keeps it running on the server:
tmux new -s work # start a named session
# Ctrl+B then D to detach
tmux attach -t work # reattach later, even from another machine
Quick reference
Ctrl+Alt+T open a terminal
ssh user@host terminal on a remote server
pwd, ls -lah, cd current directory, list it, change it
man cmd, cmd --help documentation
Tab, Ctrl+R completion, history search
Ctrl+C, Ctrl+D stop command, end input or log out
Ctrl+Shift+C / V copy / paste
cmd > file save output
cmd1 | cmd2 pipe output into another command
cmd1 && cmd2 run cmd2 only if cmd1 succeeded
sudo cmd run as root
tmux keep sessions alive across disconnects
