Linux commands are text instructions that let you work with files, programs and servers. Start with pwd, ls, cd, mkdir, cp, mv and cat. This guide explains each group with examples you can try in a practice folder.
A shell is the program that reads your command. Bash is a common shell on Linux. The terminal is the window where you type. Most examples here also work in Windows Subsystem for Linux.
Linux commands cheat sheet
| Task | Command |
|---|---|
| Show current folder | pwd |
| List files | ls -la |
| Change folder | cd folder |
| Make a folder | mkdir folder |
| Create an empty file | touch file.txt |
| Show a file | cat file.txt |
| Copy a file | cp old.txt new.txt |
| Move or rename | mv old.txt new.txt |
| Remove a file | rm file.txt |
| Find text | grep "word" file.txt |
| Change permissions | chmod 644 file.txt |
| See processes | ps aux |
| See disk space | df -h |
| Get help | man ls or ls --help |
A command often has three parts:
ls -l /var/log
ls is the command. -l is an option that changes how it works. /var/log is the argument, or the thing it works on. Linux file names are normally case-sensitive, so Notes.txt and notes.txt are different.
Move around and work with files
Make a safe practice folder:
mkdir -p "$HOME/linux-practice"
cd "$HOME/linux-practice"
pwd
$HOME is your home folder. mkdir -p makes the folder if it does not exist. The output path depends on your user name.
These path signs save typing:
| Sign | Meaning |
|---|---|
/ |
Start of the Linux file system |
. |
Current folder |
.. |
Parent folder |
~ |
Your home folder |
- with cd |
Previous folder |
Create, view, copy and rename a file:
printf "Java\nSQL\nLinux\n" > skills.txt
cat skills.txt
cp skills.txt backup.txt
mv backup.txt skills-copy.txt
ls
The two commands that print text give:
Java
SQL
Linux
skills-copy.txt
skills.txt
> writes output to a file and replaces old content. Use >> to add to the end.
| View command | Best for |
|---|---|
cat file |
A short file |
less file |
A long file; press q to leave |
head -n 5 file |
First five lines |
tail -n 5 file |
Last five lines |
tail -f file |
New log lines as they arrive |
Common mistake:
rmdoes not usually send a file to a recycle bin. Check withpwdandlsbefore removing it. Do not runrm -rfwith a path you do not fully understand.
Search, pipes and text
Make a small log:
cat > app.log <<'EOF'
INFO server started
ERROR database timeout
INFO user signed in
ERROR database timeout
WARN disk almost full
EOF
Find errors with line numbers:
grep -n "ERROR" app.log
Output:
2:ERROR database timeout
4:ERROR database timeout
Count them with grep -c "ERROR" app.log, which prints 2. Use grep -i to ignore letter case and grep -r "word" folder to search a folder.
A pipe, written |, sends one command's output to the next:
cut -d' ' -f1 app.log | sort | uniq -c
Output, with spaces at the left:
2 ERROR
2 INFO
1 WARN
cut takes the first word, sort puts equal words together and uniq -c counts them. Sort first because uniq joins only neighbouring equal lines.
Useful text commands:
| Command | Purpose |
|---|---|
wc -l app.log |
Count lines |
sort file |
Sort lines |
cut -d',' -f2 data.csv |
Show the second simple CSV field |
sed 's/ERROR/Error/' app.log |
Print text with a replacement |
awk '{print $1}' app.log |
Print the first field |
find . -name "*.txt" |
Find files by name |
Quote "*.txt" in find. Otherwise the shell may replace the star with file names before find sees it.
File permissions and users
Run this in a Linux home folder:
touch report.txt
chmod 640 report.txt
ls -l report.txt
The permissions start with -rw-r-----. Read them in groups of three after the first character:
| Who | Letters | Number | Access |
|---|---|---|---|
| Owner | rw- |
6 | Read and write |
| Group | r-- |
4 | Read |
| Others | --- |
0 | None |
Read is 4, write is 2 and execute is 1. Add the numbers: 4 + 2 = 6. A script with mode 755 lets its owner read, write and run it. Others can read and run it.
chmod changes permissions. chown changes the owner, and often needs administrator rights. whoami shows your user name. id shows your user and groups.
sudo command runs one command with extra rights if you are allowed to use it. Do not add sudo only because a command failed. Read the error first.
Interview note: Mode 777 gives everyone full access. It may make an error disappear, but it can let the wrong user change a file. Give only the access needed.
Processes, memory and disk
| Command | What it shows or does |
|---|---|
ps aux |
Running processes |
top |
Live CPU and memory; press q to leave |
kill 1234 |
Asks process 1234 to stop |
kill -9 1234 |
Forces it to stop |
free -h |
Memory use on Linux |
df -h |
Free space by file system |
du -sh folder |
Space used by one folder |
uptime |
Running time and load |
Try normal kill first, so a program can close its files. Use -9 only when it does not stop. Check the process ID before either command.
Run a program in the background by adding &:
sleep 30 &
jobs
kill %1
%1 refers to job 1 in this shell. The job number may differ if you already have other jobs, so use the number from jobs.
Linux commands for DevOps and servers
DevOps work often means finding why a service failed. These commands are for a server you are allowed to use:
| Task | Command |
|---|---|
| Open a remote shell | ssh user@server |
| Copy to a server | scp app.jar user@server:/tmp/ |
| See IP addresses | ip addr |
| See listening ports | ss -tulpn |
| Check a web response | curl -I https://example.com |
| Check a service | systemctl status nginx |
| Restart a service | sudo systemctl restart nginx |
| Follow service logs | journalctl -u nginx -f |
| Pack a folder | tar -czf app.tar.gz app/ |
| Extract it | tar -xzf app.tar.gz |
systemctl works on systems that use systemd. Package commands also depend on the Linux type:
- Ubuntu or Debian:
sudo apt update, thensudo apt install nginx. - Fedora or Red Hat based systems:
sudo dnf install nginx.
Here is a safe order when a website is down: check its response with curl, see the service status, read recent logs, check its port, then check disk and memory. Restarting first may hide the clue you need.
Pro tip: Before you run a command found online, look up each option with
manor--help. Be extra careful with a command that uses sudo, deletes data or pipes a downloaded file into a shell.
Linux commands practice with a small script
Use the log you made earlier. Create count-errors.sh:
#!/usr/bin/env bash
set -u
file="${1:-app.log}"
if [[ ! -f "$file" ]]; then
echo "File not found: $file" >&2
exit 1
fi
total=$(wc -l < "$file")
errors=$(grep -c "ERROR" "$file" || true)
echo "Lines: $total"
echo "Errors: $errors"
Run it:
bash count-errors.sh app.log
Output:
Lines: 5
Errors: 2
The first argument becomes the file name. If you give no argument, the script uses app.log. Quotes protect file names with spaces. exit 1 tells the caller that the script failed.
Do these Linux commands practice tasks without looking above:
- Make a folder named
reportswith three text files. - Copy one file and give the copy a new name.
- Find all lines with "timeout" in your log.
- Show only the last two log lines.
- Count the number of INFO lines.
- Find files with the
.txtending. - Make a file readable by its owner and group, but nobody else.
- Show which process uses the most CPU.
Check each result with a different command. For example, use ls -l to check a permission change.
Linux commands practice online and at home
You can practise Linux commands online without changing your main computer:
| Option | Good for |
|---|---|
| Linux Survival | First file and folder commands |
| OverTheWire Bandit | Solving small shell puzzles over SSH |
| Killercoda | Short Linux and DevOps labs |
| WSL on Windows | Daily practice beside Windows tools |
| Virtual machine | A full Linux system you can reset |
Online labs may have time limits or need an account. Check their current rules. Never use commands from a hacking lab on a system without permission.
A useful first week is simple: files on days 1 and 2, text on days 3 and 4, permissions on day 5, processes on day 6, and the script on day 7. Keep your own Linux commands list with one example and one safe check for each command.
Once the terminal feels normal, learn Git commands. Then follow the DevOps engineer roadmap, learn Docker basics, or test yourself with DevOps interview questions. If your goal is cloud work, see the cloud engineer roadmap.

