Tech News, Tech & Coding · Free Online Tools

IT Question Answer
Tools
Back to Cheat Sheets
Linux Terminal Commands Cheat Sheet for Beginners

Linux Terminal Commands Cheat Sheet for Beginners

Cheat SheetsBy Muhammad Fareed
linuxterminalbashcommands

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

CommandWhat it doesExample
pwdShows the current folderpwd
lsLists filesls -la (long format, hidden files)
cdChanges foldercd ~/projects
mkdirCreates a foldermkdir -p app/src
cpCopies filescp -r src backup
mvMoves or renamesmv old.txt new.txt
rmDeletes filesrm -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.txt prints a whole file.
  • less file.txt lets you scroll through a long file; press q to quit.
  • head -n 20 file.txt and tail -n 20 file.txt show the first or last lines.
  • tail -f app.log follows a log file as new lines arrive.
  • nano file.txt opens 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.sh makes a script executable.
  • chmod 644 file.txt gives the owner read and write, and everyone else read only.
  • chown user:group file.txt changes the owner.
  • sudo command runs a command with administrator rights. Use it only when you need it.

Searching

  • grep "error" app.log finds lines containing a word; add -i to ignore case and -r to search folders.
  • find . -name "*.js" finds files by name.
  • which node shows where a program is installed.

Processes and disk

  • ps aux lists running processes, and top shows live usage.
  • kill 1234 stops a process by ID; kill -9 1234 forces it.
  • df -h shows disk space, and du -sh folder shows how large a folder is.

Networking

  • ping example.com checks that a host answers.
  • curl -I https://example.com fetches response headers.
  • ss -tulpn lists 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

  1. Press Tab to complete names.
  2. Press the up arrow or use Ctrl+R to search your history.
  3. Use man command or command --help to read the options.
  4. Test destructive commands on a copy first.

Package management by distribution

TaskDebian / UbuntuFedora / RHELArch
Refresh package listssudo apt updatesudo dnf check-updatesudo pacman -Sy
Installsudo apt install gitsudo dnf install gitsudo pacman -S git
Upgrade allsudo apt upgradesudo dnf upgradesudo pacman -Syu
Removesudo apt remove gitsudo dnf remove gitsudo 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 -rf with a variable that may be empty, which can delete far more than intended. Double-check paths and avoid running as root.
  • Using chmod 777 to 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.md and README.md are 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.