
Linux Terminal Commands Cheat Sheet for Beginners
Short answer: this cheat sheet lists the Linux commands you will use most often, grouped by task: moving around, handling files, reading text, changing permissions, finding things, managing processes and checking the network. Each command comes with a short example.
Navigation and files
| Command | What it does | Example |
|---|---|---|
pwd | Shows the current folder | pwd |
ls | Lists files | ls -la (long format, hidden files) |
cd | Changes folder | cd ~/projects |
mkdir | Creates a folder | mkdir -p app/src |
cp | Copies files | cp -r src backup |
mv | Moves or renames | mv old.txt new.txt |
rm | Deletes files | rm -r build |
Be careful with rm -r: there is no trash can, and deleted files are not easy to recover.
Reading and editing text
cat file.txtprints a whole file.less file.txtlets you scroll through a long file; pressqto quit.head -n 20 file.txtandtail -n 20 file.txtshow the first or last lines.tail -f app.logfollows a log file as new lines arrive.nano file.txtopens a simple editor.
Permissions and ownership
Run ls -l to see permissions such as -rwxr-xr--. The three groups are the owner, the group and everyone else, and each can have read (r), write (w) and execute (x).
chmod +x script.shmakes a script executable.chmod 644 file.txtgives the owner read and write, and everyone else read only.chown user:group file.txtchanges the owner.sudo commandruns a command with administrator rights. Use it only when you need it.
Searching
grep "error" app.logfinds lines containing a word; add-ito ignore case and-rto search folders.find . -name "*.js"finds files by name.which nodeshows where a program is installed.
Processes and disk
ps auxlists running processes, andtopshows live usage.kill 1234stops a process by ID;kill -9 1234forces it.df -hshows disk space, anddu -sh foldershows how large a folder is.
Networking
ping example.comchecks that a host answers.curl -I https://example.comfetches response headers.ss -tulpnlists listening ports.
Pipes and redirection
A pipe sends the output of one command into another. For example, ps aux | grep node lists processes and keeps only those containing "node". Redirection saves output: ls > files.txt overwrites a file, and ls >> files.txt appends to it. Combining small commands this way is the main strength of the shell.
Habits that save time
- Press
Tabto complete names. - Press the up arrow or use
Ctrl+Rto search your history. - Use
man commandorcommand --helpto read the options. - Test destructive commands on a copy first.
Package management by distribution
| Task | Debian / Ubuntu | Fedora / RHEL | Arch |
|---|---|---|---|
| Refresh package lists | sudo apt update | sudo dnf check-update | sudo pacman -Sy |
| Install | sudo apt install git | sudo dnf install git | sudo pacman -S git |
| Upgrade all | sudo apt upgrade | sudo dnf upgrade | sudo pacman -Syu |
| Remove | sudo apt remove git | sudo dnf remove git | sudo pacman -R git |
Archives and file transfer
tar -czf backup.tar.gz project/ # create a compressed archive
tar -xzf backup.tar.gz # extract it
zip -r site.zip public/ # zip a folder
unzip site.zip
scp file.txt user@server:/home/user/ # copy a file to a server over SSH
rsync -avz project/ user@server:/srv/project/ # sync only changed files
A small shell script
Once you repeat a sequence of commands, save it as a script:
#!/usr/bin/env bash
set -euo pipefail # stop on errors and undefined variables
backup_dir="$HOME/backups"
mkdir -p "$backup_dir"
stamp=$(date +%Y-%m-%d)
tar -czf "$backup_dir/notes-$stamp.tar.gz" "$HOME/notes"
echo "Backup saved to $backup_dir"
Make it executable with chmod +x backup.sh and run it with ./backup.sh. Quote variables like "$backup_dir" so paths with spaces work.
Common mistakes
- Running
rm -rfwith a variable that may be empty, which can delete far more than intended. Double-check paths and avoid running as root. - Using
chmod 777to fix permission errors. It gives everyone full access; set the correct owner and minimal permissions instead. - Editing system files without a backup copy.
- Forgetting that Linux file names are case-sensitive:
Readme.mdandREADME.mdare different files.
Next, put these skills to work with Git commands, Docker containers and the DevOps cheat sheet.
Environment variables and the PATH
echo $HOME # print a variable
export API_URL="https://api.example.com" # set for this shell session
echo 'export EDITOR=nano' >> ~/.bashrc # make it permanent for bash
which python3 # where a command lives
echo $PATH # folders searched for commands
When you type a command, the shell looks through each folder listed in PATH, in order, until it finds a matching program. "Command not found" usually means the program is not installed or its folder is not on the PATH. Changes to ~/.bashrc or ~/.zshrc apply to new terminal windows, or immediately after running source ~/.bashrc.
Frequently asked questions
What is the difference between cp and mv?
cp makes a copy and leaves the original in place, while mv moves the file or renames it so only one copy remains.
How do I stop a command that is stuck?
Press Ctrl+C to interrupt it. If it keeps running, find its ID with ps and use kill.
Is it safe to use sudo?
It is safe when you understand the command. Avoid running scripts from unknown sources with sudo, because they get full control of the system.
How do I find out what a command does?
Run man command for the full manual or command --help for a short summary. Community tools such as tldr show practical examples.
What is the difference between bash and zsh?
Both are shells that read your commands. Bash is the default on many Linux distributions, while zsh is the default on recent macOS versions. Everyday commands work the same in both; differences show up in configuration files and advanced scripting features.
