50 Linux commands, one story.

You do not need to memorize hundreds of commands. Follow one server problem from the first login to the last log file, and learn each command at the moment you need it.

Get in and look around

1

ssh Reach a computer that isn't in front of you

The server is somewhere else. SSH opens a secure connection to it over the network. Give it a username, an @ symbol and the server's IP address, and you are inside.

ssh alex@203.0.113.10
2

whoami Find out who you are

You are logged in, but as which user? whoami answers in one word.

whoami
alex
3

pwd Find out where you are

pwd means Print Working Directory. It tells you your current location in the file system.

pwd
/home/alex
4

ls See what is here

Knowing where you are does not show what is around you. ls lists files and directories. Add options and you also see hidden files, permissions and sizes.

ls
ls -la
5

cd Go somewhere else

cd means Change Directory. Say where you want to go and you are there. Two dots go up one level. The tilde goes straight home.

cd /var/log
cd ..
cd ~

Build your workspace

6

mkdir Make a directory

mkdir creates folders. Add -p and Linux also creates any missing parent folders along the way.

mkdir -p linux-lab/logs
7

touch Create an empty file

Give touch a file name and it creates an empty file. Nothing fancy, and a good start.

touch notes.txt
8

echo Print text, then redirect it

echo prints text to the terminal, which seems useless until you add >. That sends the text into a file instead. If the file already has content, it is overwritten.

echo "hello linux" > notes.txt
9

nano Edit a file properly

nano is a text editor that runs inside the terminal. Type what you want, press Ctrl+O to save and Ctrl+X to exit. No mouse needed.

nano notes.txt
10

cat Print a file's contents

Did the changes save? cat prints a file straight to the terminal so you can check.

cat notes.txt
hello linux

Copy, move, delete and find

11

cp Make a backup copy

Those notes matter, so copy them before you ruin them. Give cp the original and where the copy should go.

cp notes.txt notes.bak
12

mv Move or rename

mv stands for move, but it also renames. Give the old name and the new one. Give a directory instead and the file moves there.

mv notes.txt project-notes.txt
13

rm Delete a file, carefully

Do you need the backup? rm deletes it. There is no recycle bin in a typical Linux terminal, so check the name before you press Enter.

rm notes.bak
14

find Search for files

You forgot where you saved the file. find searches directories by name, type, size and even modification time.

find ~ -name "project-notes.txt"
find /var/log -size +100M
15

file Identify a file's type

File names can mislead. file inspects the content and tells you if it is text, an image, a program or something else.

file project-notes.txt
project-notes.txt: ASCII text
16

stat Read a file's details

Need more? stat shows the size, permissions and timestamps. It is handy when you are checking whether something changed.

stat project-notes.txt

Read large files without the flood

17

less Scroll through a big file

cat on a file with thousands of lines floods your terminal. less opens a scrollable view instead. Press q to leave.

less /var/log/syslog
19

tail Show the end of a file

When you are troubleshooting, the newest log lines matter most. tail shows the end of a file. Add -f and new lines appear in real time as they are written.

tail -n 20 app.log
tail -f app.log

Pipes and text tools

20

grep Find matching lines

The app writes hundreds of log lines, but you only care about errors. grep prints only the lines that contain what you search for.

grep "error" app.log
21

wc Count lines and words

wc means word count. With -l it counts lines. Notice the vertical bar below. That is a pipe, and it sends one command's output into the next. You will see it a lot.

grep "error" app.log | wc -l
42
22

sort Put lines in order

A list of HTTP status codes is all mixed up. sort puts it in order so identical lines sit next to each other.

sort status-codes.txt
23

uniq Collapse and count duplicates

uniq groups lines that are next to each other and match. With -c it counts them. That is why sort comes first.

sort status-codes.txt | uniq -c
91 200
 6 404
 3 500
24

cut Pull out one column

A CSV has an IP address and a status code on each line. cut takes only the field you ask for. Here the comma is the separator and we want field 2.

cut -d',' -f2 requests.csv
25

awk Filter and process columns

awk is a powerful text processing tool. Tell it to find rows where field 2 equals 500 and print field 1, and you get the IP addresses behind the failed requests. No spreadsheet needed.

awk -F',' '$2 == 500 {print $1}' requests.csv
26

sed Replace text in a stream

sed is the stream editor. Here it swaps every staging for production in the output. The original file is not changed. You are only previewing the result.

sed 's/staging/production/g' config.txt

Permissions and ownership

27

chmod Change what a file allows

You wrote a deploy script and Linux says Permission denied. Permissions control what users can do. chmod changes them. Add execute and the script can run.

chmod +x deploy.sh
./deploy.sh
28

id See your user and groups

Still blocked? Maybe the problem is the user. id shows your user ID, group ID and every group you belong to. Linux uses these to decide who can access what.

id
29

sudo Run one command as admin

Some actions need administrator rights. sudo runs a command with elevated privileges, usually as root. With great power comes the ability to wreck your system, so be careful.

sudo systemctl restart nginx
30

chown Change a file's owner

Every file has an owner and a group. chown changes them. This fixes cases where an app cannot read files because the wrong user owns them.

sudo chown alex:alex deploy.sh

Processes and system health

31

ps Snapshot of running processes

Sometimes the app itself misbehaves. ps lists processes with their process ID (PID), CPU use and memory use. You will need the PID to stop one.

ps aux
ps aux | grep nginx
32

top Watch processes live

ps is a snapshot. top keeps updating, so you can watch which processes use the most CPU and memory right now. One process is hogging the CPU. Press q to exit.

top
33

kill Stop a process

Found a stuck test program? kill takes its PID. Despite the name, it first sends a polite signal asking the process to shut down.

kill 4821
34

free Check memory

Still slow? Maybe memory ran out. free shows total, available and swap memory. Add -h for human-readable numbers.

free -h
35

df Check disk space

Memory is not the only thing that runs out. df shows how much space is used and free on each file system.

df -h
36

du Find what fills the disk

The disk is full, but with what? du estimates the space used by files and directories. Here it totals the logs folder.

du -sh logs/
37

uptime See how long it has been running

Before you blame the app, check the server. uptime shows how long it has been up, how many users are logged in and the recent load. Months of uptime or ten minutes since a reboot, both are useful clues.

uptime
38

uname Identify the system

What kind of Linux is this? With -a, uname shows the kernel release and machine architecture. Good for explaining why software works on one machine and not another.

uname -a

The network

39

ip Inspect network settings

The system looks fine but the app does not answer. Maybe it is the network. ip shows and manages interfaces and addresses. There is the server's address.

ip addr
40

ping Test basic reachability

Can you reach anything? ping sends packets and waits for replies. Here, four to Cloudflare's public DNS. Some networks block ping, so a silence does not always mean offline.

ping -c 4 1.1.1.1
41

curl Talk to a website from the terminal

To test a real website, use curl. Here it requests only the response headers. Check status codes, inspect headers, test APIs. A favorite of back-end developers.

curl -I https://hriday.xyz
42

wget Download a file

Want to keep the response instead of just looking? wget downloads from a URL. Here it saves a web page into a local file.

wget -O page.html https://hriday.xyz
43

ss See which ports are listening

The network works, but is anything listening on the port you expect? ss shows sockets. With the right options you see listening TCP and UDP ports. App meant to use 8080? Check here.

ss -tuln
44

scp Copy files between machines

scp is Secure Copy. It sends files to another machine over SSH. Give it the local file and the remote destination.

scp project-notes.txt alex@203.0.113.10:/home/alex/

Archives and services

45

tar Bundle many files into one

Copying files one by one gets old. tar packs files and directories into a single archive. Here it creates a compressed one with notes, config and logs.

tar -czf project.tar.gz notes config logs
46

gzip Compress a single file

For one huge log file, gzip compresses it to save space. The -k option keeps the original too.

gzip -k app.log
47

systemctl Manage services

On systems with systemd, systemctl manages services. Check Nginx, then start, stop or restart it when needed.

systemctl status nginx
sudo systemctl restart nginx
48

journalctl Read service logs

What if it fails again right away? journalctl reads the logs systemd collects. Here, the last 30 entries for Nginx. A bad config, a busy port or a missing file will often show up here.

journalctl -u nginx -n 30

Never memorize everything

49

man Read the manual

You do not need to remember every option. man followed by a command opens its documentation. Even experienced engineers look things up all the time.

man grep
50

history Recall past commands

Used the right command but cannot remember it? history lists what you ran before. Pipe it into tail to see only the last ten.

history | tail -n 10