Ravindra BagaleCourses & study guides मराठी Track your progress

Linux Commands A-Z Part 7: strace, sudo, systemctl, tail, tar, tmux, top, uname and More with Examples

This is Part 7 of the Linux Commands A-Z reference: strace to uname. These are the commands you use to trace a failing program, switch users and run admin commands safely, add swap, tune the kernel, manage services, read live logs, make backups, save output while you watch it, write conditions in scripts, measure time, set the clock, keep sessions alive, watch CPU and memory, clean text, trace network paths, see folder trees, empty huge logs, find what a command name really is, raise limits, set default permissions, unmount disks and identify the kernel. Every command has why, what, an options table and step-by-step examples with real output and its meaning.

What you'll learn in this chapter

  • Debug failing programs with strace and see live load with top
  • Use su and sudo safely and know who you are
  • Add swap with swapon and tune the kernel with sysctl and ulimit
  • Manage services with systemctl and read logs with tail
  • Make backups with tar and keep logs with tee
  • Write safer scripts with test, time, tr and type
  • Keep long jobs alive with tmux and trace networks with traceroute
  • Handle files and disks with tree, truncate, umask, umount, uname and timedatectl

1. An everyday example: a Pune wedding caterer

Why do we need this?

The head caterer watches each cook to see where the delay is, hands the store-room key to a helper for one task only, brings extra tables when the hall is full, adjusts the gas flame, starts and stops each counter, reads the latest orders from the bottom of the list, packs leftovers in boxes, keeps a copy of every order slip, checks that each dish is ready before serving, times the biryani, sets the hall clock right, and keeps the menu board in place even if he steps out.

What is it?

Watching cooks is strace and top. The store key is sudo. Extra tables are swap. The gas flame is sysctl. Counters are systemctl. Latest orders are tail. Boxes are tar. The slip copy is tee. Checking dishes is test. Timing is time. The clock is timedatectl. The menu board that stays is tmux.

How to do it (step by step)

Fixing a slow, failing service end to endtop: what is busysystemctl statustail -F the logstrace the processsysctl or ulimit fixRestart and verify
Each step uses a command from this part.

2. A five-minute service health check using Part 7 commands

Why do we need this?

Before the deep dives, see how these commands work together when a service misbehaves.

What is it?

Load, then service state, then logs, then system calls.

QuestionCommand
Is the box busy?top -b -n 1 | head -5
Is the service up?systemctl status app
What do the logs say?tail -n 50 /var/log/app.log
What file is it stuck on?strace -p PID
Enough open files?ulimit -n

How to do it (step by step)

  1. Run the check.
systemctl is-active billing; tail -n 1 /var/log/billing/app.log

Output:

failed
FATAL cannot open /etc/billing/app.yml: Permission denied

What it means: The service died on a config permission.

  1. Confirm and fix.
sudo -u billing test -r /etc/billing/app.yml || sudo chmod 640 /etc/billing/app.yml; sudo systemctl restart billing; systemctl is-active billing

Output:

active

What it means: Readable now, service back.

3. strace: Trace system calls

strace in depth: see what a program asks the kernel

Why do we need this?

An app fails with no useful log line. It cannot find a file, a permission is wrong, or it hangs on the network. strace shows every system call, so you see the exact file or socket that failed.

What is it?

strace runs a command (or attaches to a PID with -p) and prints each system call with its arguments and result. -f follows child processes, -e trace= filters calls, -o writes to a file, -c gives a summary table, -T shows time spent in each call.

Common options

OptionWhat it does
strace cmdTrace a new command.
-p PIDAttach to a running process.
-fFollow forks.
-e trace=openatOnly file opens.
-cSummary of calls.
-o fileSave output.

How to do it (step by step)

  1. Why does the app not start?
strace -e trace=openat ./billing 2>&1 | grep ENOENT

Output:

openat(AT_FDCWD, "/etc/billing/app.yml", O_RDONLY) = -1 ENOENT (No such file or directory)

What it means: The config file is missing at that path.

  1. Attach to a stuck process.
sudo strace -p 4120

Output:

connect(5, {sa_family=AF_INET, sin_port=htons(5432), sin_addr=inet_addr("10.0.2.9")}, 16

What it means: It waits on a database connection to 10.0.2.9:5432.

  1. Where is time spent?
strace -c -f ./report.sh

Output:

% time     seconds  usecs/call     calls    errors syscall
 71.20    0.412000        103      4000           read
 18.10    0.105000         52      2010           write

What it means: Mostly reading: many small reads.

  1. Save for later.
strace -f -o /tmp/app.trace ./app; grep -c EACCES /tmp/app.trace

Output:

3

What it means: Three permission denials to check.

Practise this in the tasks below: Practice tasks

Real use: A Hinjewadi payments team found a missing CA bundle path with strace -e trace=openat in two minutes.

4. su: Switch user

su in depth: switch user

Why do we need this?

You need to run something as the app user or as root, for example to test file access the way the service sees it.

What is it?

su starts a shell as another user. su - gives a full login environment (home, PATH). su -c runs one command. -s picks a shell, useful for system users with nologin. It asks for the target user password; sudo asks for yours.

Common options

OptionWhat it does
su - userLogin as user.
su -Become root.
su -c "cmd" userOne command.
-s /bin/bashChoose shell.
exitReturn.

How to do it (step by step)

  1. Become the app user.
sudo su - appsvc -s /bin/bash

Output:

[appsvc@web01 ~]$

What it means: A full login shell as appsvc.

  1. Test access as that user.
sudo su -s /bin/bash -c "cat /srv/app/.env" appsvc

Output:

cat: /srv/app/.env: Permission denied

What it means: The service cannot read its own env file.

  1. Check who you are.
whoami

Output:

appsvc

What it means: You are the app user now.

  1. Go back.
exit

Output:

logout

What it means: Back to your own shell.

Practise this in the tasks below: Practice tasks

Real use: A Kothrud school IT admin uses su - teacher to reproduce what a teacher sees on the lab Linux PCs.

5. sudo: Run a command as another user

sudo in depth: run as root safely

Why do we need this?

Nobody should log in as root every day. sudo gives just enough power for one command and logs who did what.

What is it?

sudo runs a command as root (or -u user) after asking for your own password. Rules live in /etc/sudoers and /etc/sudoers.d, edited only with visudo. sudo -l lists what you may run, -i opens a root login shell, -k forgets the cached password.

Common options

OptionWhat it does
sudo cmdAs root.
-u user cmdAs another user.
-lWhat can I run?
-iRoot login shell.
-kForget cached password.
visudo -fEdit a rules file safely.

How to do it (step by step)

  1. Run one admin command.
sudo systemctl restart nginx

What it means: Restarted, and logged in the secure log.

  1. What am I allowed?
sudo -l

Output:

User ravi may run the following commands on web01:
    (root) /usr/bin/systemctl restart nginx

What it means: Only one command is allowed.

  1. Run as the app user.
sudo -u appsvc touch /srv/app/tmp/test

What it means: Creates the file with the right owner.

  1. Give a team limited rights.
sudo visudo -f /etc/sudoers.d/ops

Output:

%ops ALL=(root) /usr/bin/systemctl restart app

What it means: Ops group may restart only the app.

Practise this in the tasks below: Practice tasks

Real use: A Baner bank audit checks /var/log/secure for every sudo command run on production.

6. swapon: Enable and show swap

swapon in depth: add and check swap

Why do we need this?

A small cloud server with 1 GB RAM gets killed by the OOM killer during a build. A swap file gives breathing room.

What is it?

swapon enables a swap file or partition; swapoff disables it. --show lists active swap. A swap file is made with fallocate or dd, chmod 600, then mkswap. Add it to /etc/fstab to keep it after reboot. vm.swappiness (sysctl) controls how eagerly Linux swaps.

Common options

OptionWhat it does
--showList swap.
swapon /swapfileEnable.
swapoff /swapfileDisable.
-aEnable all in fstab.
mkswap filePrepare a swap file.

How to do it (step by step)

  1. Check current swap.
swapon --show

What it means: Empty: no swap at all.

  1. Make a 2 GB swap file.
sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile && sudo mkswap /swapfile

Output:

Setting up swapspace version 1, size = 2 GiB

What it means: Ready to enable.

  1. Enable and check.
sudo swapon /swapfile; swapon --show

Output:

NAME      TYPE SIZE USED PRIO
/swapfile file   2G   0B   -2

What it means: 2 GB swap active.

  1. Keep after reboot.
echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab

Output:

/swapfile none swap sw 0 0

What it means: Survives reboot.

Practise this in the tasks below: Practice tasks

Real use: A Wakad startup added a 2 GB swap file to its t3.micro CI runner and the nightly build stopped crashing.

7. sysctl: Read and set kernel settings

sysctl in depth: tune the kernel

Why do we need this?

A busy web server runs out of connection slots, or you must enable IP forwarding for a NAT box. These are kernel settings, changed with sysctl.

What is it?

sysctl reads and writes kernel parameters under /proc/sys. sysctl name reads, -w name=value changes until reboot, a file in /etc/sysctl.d makes it permanent, and sysctl --system reloads all files. -a lists everything.

Common options

OptionWhat it does
sysctl nameRead.
-w name=valueSet now.
-aList all.
--systemReload all files.
-p fileLoad one file.

How to do it (step by step)

  1. Read a value.
sysctl net.ipv4.ip_forward

Output:

net.ipv4.ip_forward = 0

What it means: Forwarding is off.

  1. Turn it on now.
sudo sysctl -w net.ipv4.ip_forward=1

Output:

net.ipv4.ip_forward = 1

What it means: Works until reboot.

  1. Make it permanent.
echo "net.ipv4.ip_forward = 1" | sudo tee /etc/sysctl.d/90-nat.conf; sudo sysctl --system | tail -1

Output:

net.ipv4.ip_forward = 1

What it means: Loaded from the file.

  1. Lower swappiness.
sudo sysctl -w vm.swappiness=10

Output:

vm.swappiness = 10

What it means: The database server keeps more in RAM.

Practise this in the tasks below: Practice tasks

Real use: A Magarpatta gaming company raises net.core.somaxconn on its match servers before every tournament.

8. systemctl: Manage services

systemctl in depth: manage services

Why do we need this?

Nginx, the database, your own app: on modern Linux every service is a systemd unit. Start, stop, enable at boot and see why it failed, all with systemctl.

What is it?

systemctl start, stop, restart and reload control a unit now; enable and disable control boot; status shows state plus the last log lines; is-active and is-enabled suit scripts; daemon-reload reads changed unit files; list-units --failed shows broken ones; edit creates an override.

Common options

OptionWhat it does
status unitState and logs.
start/stop/restartControl now.
enable --nowBoot and start.
is-activeFor scripts.
daemon-reloadReload unit files.
--failedBroken units.

How to do it (step by step)

  1. Check a service.
systemctl status nginx

Output:

● nginx.service - The nginx HTTP and reverse proxy server
     Active: active (running) since Tue 2026-10-27 09:12:03 IST

What it means: Running since this morning.

  1. Find failures.
systemctl --failed

Output:

  UNIT          LOAD   ACTIVE SUB    DESCRIPTION
● billing.service loaded failed failed Billing API

What it means: The billing API is down.

  1. Fix and start at boot.
sudo systemctl daemon-reload; sudo systemctl enable --now billing

Output:

Created symlink /etc/systemd/system/multi-user.target.wants/billing.service

What it means: Running now and after reboot.

  1. Script check.
systemctl is-active billing

Output:

active

What it means: One word, exit code 0.

Practise this in the tasks below: Practice tasks

Real use: A Hadapsar e-commerce warehouse runs its label printer service as a systemd unit with Restart=always.

9. tail: Show the last lines or follow a log

tail in depth: end of files and live logs

Why do we need this?

When a deploy goes wrong you want the newest log lines, and you want to watch them arrive while you test.

What is it?

tail prints the last 10 lines. -n N sets the count, -n +N starts from line N, -f follows new lines, -F follows even after log rotation, -c counts bytes. Pipe into grep to filter a live stream.

Common options

OptionWhat it does
-n 50Last 50 lines.
-n +2From line 2 (skip header).
-fFollow.
-FFollow across rotation.
-c 200Last 200 bytes.

How to do it (step by step)

  1. Newest lines.
tail -n 3 /var/log/nginx/error.log

Output:

2026/10/27 10:02:11 [error] connect() failed (111: Connection refused) while connecting to upstream

What it means: Upstream app is down.

  1. Watch live.
tail -F /var/log/app/app.log | grep --line-buffered ERROR

Output:

ERROR order 5512 payment timeout

What it means: Only errors, as they happen.

  1. Skip a CSV header.
tail -n +2 sales.csv | head -2

Output:

2026-10-01,Pune,4200
2026-10-01,Nashik,3100

What it means: Data rows only.

  1. Two files at once.
tail -n 1 app1.log app2.log

Output:

==> app1.log <==
started
==> app2.log <==
started

What it means: Headers show each file.

Practise this in the tasks below: Practice tasks

Real use: A Shivajinagar hospital help desk keeps tail -F on the PACS log during every scanner upgrade.

10. tar: Pack files into an archive

tar in depth: archives and backups

Why do we need this?

Back up a website folder, ship a release, move configs between servers: tar packs many files into one, keeping permissions.

What is it?

tar c creates, x extracts, t lists; f names the archive; z gzip, j bzip2, J xz compress; v verbose; -C changes folder; --exclude skips paths; -p keeps permissions on extract. Full compression comparison is in the compression chapter.

Common options

OptionWhat it does
czf a.tgz dirCreate gzip archive.
tzf a.tgzList.
xzf a.tgz -C dirExtract into dir.
cJf a.txzxz archive.
--exclude=PATSkip.
-pKeep permissions.

How to do it (step by step)

  1. Back up a site.
tar czf site-2026-10-27.tgz --exclude="*.log" /var/www/shop

Output:

tar: Removing leading `/' from member names

What it means: Normal: paths are stored relative.

  1. Look inside.
tar tzf site-2026-10-27.tgz | head -3

Output:

var/www/shop/
var/www/shop/index.html
var/www/shop/css/

What it means: Contents listed without extracting.

  1. Restore elsewhere.
mkdir /tmp/restore && tar xzf site-2026-10-27.tgz -C /tmp/restore

What it means: Restored under /tmp/restore/var/www/shop.

  1. One file only.
tar xzf site-2026-10-27.tgz var/www/shop/index.html

What it means: Pulls just that file.

Practise this in the tasks below: Practice tasks

Real use: A Deccan chartered-accountant office tars its client folders every Friday and copies the archive to S3.

11. tee: Write output to screen and file

tee in depth: see output and save it

Why do we need this?

You run an upgrade and want to watch the output and keep a log at the same time. Or you need sudo to write a file that redirection cannot.

What is it?

tee copies standard input to the screen and to one or more files. -a appends instead of overwriting. sudo tee writes root-owned files because tee itself runs as root, unlike > which runs in your shell.

Common options

OptionWhat it does
cmd | tee fileScreen and file.
-aAppend.
tee f1 f2Two files.
| sudo tee fileWrite as root.
> /dev/nullHide screen copy.

How to do it (step by step)

  1. Log an upgrade.
sudo dnf -y update 2>&1 | tee update-2026-10-27.log | tail -1

Output:

Complete!

What it means: You saw it and saved it.

  1. Append daily.
date | tee -a checks.log

Output:

Tue Oct 27 10:30:00 IST 2026

What it means: Adds a line, keeps old ones.

  1. Write a root file.
echo "10.0.1.5 db01" | sudo tee -a /etc/hosts

Output:

10.0.1.5 db01

What it means: sudo echo > /etc/hosts would fail.

  1. Quiet write.
echo "vm.swappiness = 10" | sudo tee /etc/sysctl.d/80-swap.conf > /dev/null

What it means: Written without echoing.

Practise this in the tasks below: Practice tasks

Real use: A Chakan auto plant logs every PLC firmware push with tee so the shift engineer can watch and QA can audit.

12. test: Check files and values

test in depth: conditions in scripts

Why do we need this?

Before a script deletes, copies or deploys, it must check: does the file exist, is the folder writable, is the number bigger than the limit?

What is it?

test (or [ ]) checks a condition and returns exit code 0 (true) or 1 (false). Files: -f file, -d dir, -e exists, -s not empty, -r/-w/-x. Strings: = != -z -n. Numbers: -eq -ne -gt -lt -ge -le. Bash also has [[ ]] with pattern matching.

Common options

OptionWhat it does
-f pathRegular file.
-d pathDirectory.
-z "$v"Empty string.
a -gt bGreater (numbers).
! exprNot.
[[ $x == *.log ]]Pattern (bash).

How to do it (step by step)

  1. Does a file exist?
test -f /etc/app.conf && echo yes || echo no

Output:

no

What it means: Create the config before starting.

  1. Disk guard.
use=$(df --output=pcent / | tail -1 | tr -dc 0-9); [ "$use" -gt 90 ] && echo "disk full"

Output:

disk full

What it means: Stop the backup before it fills the disk.

  1. Empty variable.
[ -z "$DB_HOST" ] && echo "DB_HOST missing"

Output:

DB_HOST missing

What it means: Fail early with a clear message.

  1. Exit code.
[ -d /srv/app ]; echo $?

Output:

0

What it means: 0 means true.

Practise this in the tasks below: Practice tasks

Real use: A Kalyani Nagar travel portal deploy script checks [ -s build/index.html ] before switching traffic.

13. time: Measure how long a command takes

time in depth: measure how long a command takes

Why do we need this?

Is the new query faster? Did compression slow the backup? Measure instead of guessing.

What is it?

time runs a command and prints real (wall clock), user (CPU in your code) and sys (CPU in the kernel). If real is much bigger than user+sys, the command waited on disk or network. /usr/bin/time -v gives memory use too.

Common options

OptionWhat it does
time cmdReal, user, sys.
/usr/bin/time -vMax memory too.
TIMEFORMAT=%ROnly seconds (bash).
time ( a; b )Time a group.

How to do it (step by step)

  1. Time a backup.
time tar czf db.tgz /var/lib/pgsql/dump

Output:

real    1m42.311s
user    1m30.020s
sys     0m6.144s

What it means: CPU bound: compression is the cost.

  1. Network wait.
time curl -s https://api.example.in/report > /dev/null

Output:

real    0m4.902s
user    0m0.020s
sys     0m0.011s

What it means: Almost all waiting: the API is slow.

  1. Peak memory.
/usr/bin/time -v python3 etl.py 2>&1 | grep Maximum

Output:

Maximum resident set size (kbytes): 812344

What it means: About 800 MB at peak.

  1. Compare two.
time gzip -k big.log; time xz -k big.log

Output:

real 0m3.1s
real 0m21.7s

What it means: xz is 7x slower here.

Practise this in the tasks below: Practice tasks

Real use: A Pimpri analytics team times its nightly ETL so it always ends before the 6 AM dashboard refresh.

14. timedatectl: Manage time and time zone

timedatectl in depth: time zone and clock sync

Why do we need this?

Logs in UTC, users in IST, a token rejected because the clock is 3 minutes off: time settings matter.

What is it?

timedatectl shows local time, UTC, time zone and whether NTP sync is on. set-timezone changes the zone, list-timezones lists them, set-ntp true turns on sync (chronyd or timesyncd). set-time sets the clock by hand when NTP is off.

Common options

OptionWhat it does
timedatectlStatus.
set-timezone Asia/KolkataSet zone.
list-timezonesList zones.
set-ntp trueEnable sync.
set-time "2026-10-27 10:00"Manual time.

How to do it (step by step)

  1. Check.
timedatectl

Output:

               Local time: Tue 2026-10-27 04:40:10 UTC
                Time zone: UTC (UTC, +0000)
System clock synchronized: yes

What it means: Synced, but in UTC.

  1. Find the zone.
timedatectl list-timezones | grep Kolkata

Output:

Asia/Kolkata

What it means: Exact name to use.

  1. Set IST.
sudo timedatectl set-timezone Asia/Kolkata; date

Output:

Tue Oct 27 10:10:10 IST 2026

What it means: Now in IST.

  1. Turn on sync.
sudo timedatectl set-ntp true

What it means: Clock stays correct.

Practise this in the tasks below: Practice tasks

Real use: A Viman Nagar airline-catering firm keeps all kitchen servers on Asia/Kolkata with NTP so meal labels show correct times.

15. tmux: Split and keep terminal sessions

tmux in depth: sessions that survive disconnects

Why do we need this?

Your Wi-Fi drops in the middle of a database migration. With tmux the job keeps running and you reattach exactly where you were.

What is it?

tmux runs terminals inside a server process. new -s names a session, detach with Ctrl-b d, ls lists sessions, attach -t returns, Ctrl-b % and Ctrl-b " split panes, kill-session ends one. It is the modern choice over screen.

Common options

OptionWhat it does
new -s nameNew session.
Ctrl-b dDetach.
lsList sessions.
attach -t nameReattach.
Ctrl-b %Split side by side.
kill-session -t nameEnd session.

How to do it (step by step)

  1. Start a named session.
tmux new -s migrate

Output:

[migrate] 0:bash*

What it means: You are inside tmux.

  1. Detach and list.
tmux ls

Output:

migrate: 1 windows (created Tue Oct 27 11:00:02 2026)

What it means: Still running after you left.

  1. Come back.
tmux attach -t migrate

Output:

(migration output continues)

What it means: Same screen as before.

  1. Clean up.
tmux kill-session -t migrate

What it means: Session gone.

Practise this in the tasks below: Practice tasks

Real use: A Kharadi SaaS on-call engineer runs every production migration inside tmux after losing one to a VPN drop.

16. top: Live view of processes

top in depth: live CPU and memory view

Why do we need this?

The server feels slow. In five seconds top tells you whether CPU, memory or I/O wait is the problem and which process causes it.

What is it?

top refreshes a table of processes. The header shows load average, CPU split (us, sy, wa, st) and memory. Keys: P sort by CPU, M by memory, k kill, 1 per-CPU view, q quit. -b -n 1 prints once for scripts; -p watches PIDs; -u a user.

Common options

OptionWhat it does
P / MSort CPU / memory.
1Each CPU.
-b -n 1One batch print.
-p PIDWatch PIDs.
-u userOne user.
wa / stIO wait / stolen.

How to do it (step by step)

  1. Read the header.
top -b -n 1 | head -3

Output:

top - 11:20:01 up 12 days,  load average: 7.81, 6.20, 3.10
Tasks: 212 total,   3 running
%Cpu(s): 12.0 us,  3.1 sy,  0.0 ni,  4.2 id, 80.5 wa,  0.0 st

What it means: 80% IO wait: the disk is the bottleneck.

  1. Top memory users.
top -b -n 1 -o %MEM | sed -n 8,9p

Output:

   2210 mysql  20  0  6.1g  4.8g  S  2.0 61.3  java

What it means: MySQL holds 61% of RAM.

  1. Watch one process.
top -p 2210

Output:

(live view of PID 2210)

What it means: Focused view.

  1. Cloud steal.
top -b -n 1 | grep Cpu

Output:

%Cpu(s): 40.0 us, 2.0 sy, 0.0 wa, 35.0 st

What it means: 35% stolen: the burst instance ran out of credits.

Practise this in the tasks below: Practice tasks

Real use: A Swargate bus-ticketing team saw 35% steal in top and moved from t3 to m6i instances before Diwali.

17. tr: Translate or delete characters

tr in depth: translate and delete characters

Why do we need this?

Uppercase a code, turn commas into new lines, strip Windows line endings or remove digits: small text fixes in a pipe.

What is it?

tr reads stdin and maps characters from set1 to set2. -d deletes characters, -s squeezes repeats, -c uses the complement. Classes like [:lower:] [:upper:] [:digit:] [:space:] help. tr works on characters, not words; use sed for words.

Common options

OptionWhat it does
tr a-z A-ZUppercase.
tr "," "\n"Comma to newline.
-d "\r"Delete CR.
-s " "Squeeze spaces.
-dc "0-9"Keep only digits.

How to do it (step by step)

  1. Uppercase.
echo "pune-411001" | tr a-z A-Z

Output:

PUNE-411001

What it means: Codes in one case.

  1. Split a list.
echo "web1,web2,web3" | tr "," "\n"

Output:

web1
web2
web3

What it means: One host per line for a loop.

  1. Fix Windows files.
tr -d "\r" < export.csv > clean.csv; file clean.csv

Output:

clean.csv: ASCII text

What it means: No more CRLF.

  1. Only digits.
echo "Disk used: 91%" | tr -dc 0-9

Output:

91

What it means: Ready for a number test.

Practise this in the tasks below: Practice tasks

Real use: A Market Yard trader cleans supplier CSVs from Excel with tr -d "\r" before loading them into the stock system.

18. traceroute: Show the network path to a host

traceroute in depth: where packets stop

Why do we need this?

Ping fails or is slow. Is it your office, the ISP, or the cloud? traceroute shows each hop and the delay to it.

What is it?

traceroute sends packets with rising TTL so each router replies in turn. Each line is a hop with three timings; * means no reply. -n skips DNS, -T uses TCP (good through firewalls), -p sets the port, -m max hops. tracepath and mtr are alternatives.

Common options

OptionWhat it does
-nNo DNS.
-T -p 443TCP to port.
-m 15Max hops.
-w 2Wait seconds.
mtrLive version.

How to do it (step by step)

  1. Trace a site.
traceroute -n api.example.in

Output:

1  192.168.1.1  1.1 ms
 2  10.40.0.1  6.0 ms
 3  * * *
 4  52.95.66.1  31.2 ms

What it means: Hop 3 hides ICMP but traffic passes.

  1. Through a firewall.
sudo traceroute -T -p 443 -n api.example.in | tail -1

Output:

9  13.234.10.20  33.0 ms

What it means: TCP reaches the server.

  1. Find the slow hop.
traceroute -n 8.8.8.8 | sed -n 3,4p

Output:

3  103.1.2.1  8.0 ms
 4  103.1.9.9  210.4 ms

What it means: The ISP link at hop 4 adds 200 ms.

  1. Install if missing.
sudo dnf -y install traceroute

Output:

Complete!

What it means: Ready.

Practise this in the tasks below: Practice tasks

Real use: A Bhosari factory showed its ISP a traceroute with 200 ms at their router and got the link fixed.

19. tree: Show folders as a tree

tree in depth: see folder structure

Why do we need this?

Explaining a project layout or checking that a deploy copied the right folders is easier as a tree than with many ls calls.

What is it?

tree prints a folder and its children as an indented tree. -L limits depth, -d shows only folders, -a hidden files, -h sizes, -I excludes a pattern, --du folder sizes. It may need installing.

Common options

OptionWhat it does
-L 2Two levels.
-dFolders only.
-aHidden too.
-hSizes.
-I "node_modules"Exclude.

How to do it (step by step)

  1. Project layout.
tree -L 2 shop

Output:

shop
├── app
│   ├── main.py
│   └── models.py
├── deploy
└── README.md

3 directories, 3 files

What it means: Clear picture for a new team member.

  1. Folders only.
tree -d -L 1 /etc/nginx

Output:

/etc/nginx
├── conf.d
└── default.d

What it means: Where configs live.

  1. Skip big folders.
tree -L 2 -I "node_modules|.git" web

Output:

web
├── src
└── package.json

What it means: Readable output.

  1. With sizes.
tree -h -L 1 /var/log | tail -2

Output:

└── [ 12M]  messages

4 directories, 18 files

What it means: Biggest log at a glance.

Practise this in the tasks below: Practice tasks

Real use: A Model Colony training institute pastes tree -L 2 output into every lab handout so students know where files go.

20. truncate: Shrink or grow a file to a size

truncate in depth: shrink or size files

Why do we need this?

A log has filled the disk but the app still holds it open. Deleting it does not free space; truncating it to zero does, instantly.

What is it?

truncate -s sets a file size: 0 empties it, 100M makes a sparse file, +10M grows, -10M shrinks. The inode stays the same, so open handles keep working. Use it for logs and for practice disk images.

Common options

OptionWhat it does
-s 0 fileEmpty.
-s 1G fileSet size.
-s +100MGrow.
-s -1MShrink.
-cDo not create.

How to do it (step by step)

  1. Disk full from a log.
df -h /var | tail -1

Output:

/dev/xvda1  20G  20G  0  100% /

What it means: No space left.

  1. Empty it safely.
sudo truncate -s 0 /var/log/app/debug.log; df -h /var | tail -1

Output:

/dev/xvda1  20G  12G  8.0G  60% /

What it means: 8 GB back, app still logging.

  1. Make a test disk file.
truncate -s 1G disk.img; ls -lh disk.img; du -h disk.img

Output:

-rw-r--r-- 1 ravi ravi 1.0G disk.img
0       disk.img

What it means: Sparse: 1 GB size, no space used yet.

  1. Only if it exists.
truncate -c -s 0 old.log

What it means: No new file is created.

Practise this in the tasks below: Practice tasks

Real use: A Hinjewadi call-analytics team truncates a runaway debug log at 2 AM instead of restarting the dialer.

21. type: Show how a command name is resolved

type in depth: what will actually run

Why do we need this?

You type ls or python and get something odd. Is it an alias, a function, a builtin or a file on PATH? type tells you.

What is it?

type is a shell builtin that explains how a name is resolved. -a shows every match in order, -t prints one word (alias, keyword, function, builtin, file), -P forces a PATH search. It is more accurate than which because it knows aliases and functions.

Common options

OptionWhat it does
type nameExplain.
-aAll matches.
-tOne word.
-PPATH file only.
command -vScript friendly.

How to do it (step by step)

  1. An alias?
type ll

Output:

ll is aliased to `ls -l --color=auto'

What it means: ll is an alias.

  1. Builtin.
type cd

Output:

cd is a shell builtin

What it means: No file on disk.

  1. Which python?
type -a python3

Output:

python3 is /usr/local/bin/python3
python3 is /usr/bin/python3

What it means: The /usr/local one runs first.

  1. One word.
type -t deploy

Output:

function

What it means: A shell function from your profile.

Practise this in the tasks below: Practice tasks

Real use: A Bavdhan data-science team found that type -a python3 showed a stale /usr/local build breaking their notebooks.

22. ulimit: Show and set user limits

ulimit in depth: per-process limits

Why do we need this?

Nginx logs "Too many open files" under load, or a crash leaves no core dump. Both are ulimit settings.

What is it?

ulimit shows and sets shell limits inherited by child processes: -n open files, -u processes, -c core size, -a all. -S soft and -H hard; a user can raise soft up to hard. Make limits permanent in /etc/security/limits.conf or with LimitNOFILE= in a systemd unit.

Common options

OptionWhat it does
-aAll limits.
-nOpen files.
-n 65535Raise for this shell.
-c unlimitedAllow core dumps.
-HnHard limit.

How to do it (step by step)

  1. Check open files.
ulimit -n

Output:

1024

What it means: Too low for a busy proxy.

  1. Check a running process.
grep "open files" /proc/$(pgrep -o nginx)/limits

Output:

Max open files            1024                 4096                 files

What it means: Soft 1024, hard 4096.

  1. Fix for a service.
sudo systemctl edit nginx

Output:

[Service]
LimitNOFILE=65535

What it means: Set in the unit, then restart.

  1. Allow core dumps.
ulimit -c unlimited; ./app

Output:

Segmentation fault (core dumped)

What it means: Core file for the developer.

Practise this in the tasks below: Practice tasks

Real use: A Yerawada OTT streaming team raised LimitNOFILE to 65535 on edge servers before a cricket final.

23. umask: Default permission mask

umask in depth: default permissions

Why do we need this?

New files on a shared folder come out readable by everyone, or a team cannot edit each other's files. The default mode is set by umask.

What is it?

umask removes permission bits from new files (base 666) and folders (base 777). 022 gives 644 and 755; 002 gives 664 and 775 for group work; 077 gives 600 and 700 for privacy. -S shows it as letters. Set it in ~/.bashrc or UMask= in systemd. Full permission detail is in the permissions chapter.

Common options

OptionWhat it does
umaskShow.
-SSymbolic.
umask 002Group writable.
umask 077Private.
UMask=0027systemd unit.

How to do it (step by step)

  1. Current value.
umask

Output:

0022

What it means: Files 644, folders 755.

  1. Private session.
umask 077; touch secret.txt; ls -l secret.txt

Output:

-rw------- 1 ravi ravi 0 secret.txt

What it means: Only you can read.

  1. Team folder.
umask 002; mkdir shared; ls -ld shared

Output:

drwxrwxr-x 2 ravi devs 6 shared

What it means: Group can write.

  1. Letters.
umask -S

Output:

u=rwx,g=rwx,o=rx

What it means: Same as 002.

Practise this in the tasks below: Practice tasks

Real use: A Kondhwa law firm sets umask 077 for its document server so new case files are private by default.

24. umount: Detach a filesystem

umount in depth: detach filesystems

Why do we need this?

Before you detach an EBS volume, remove a USB disk or resize a partition, the filesystem must be unmounted cleanly.

What is it?

umount takes a mount point or device. "target is busy" means a process uses it: find it with lsof or fuser -m. -l lazy detaches now and cleans up later; -f forces NFS. Never pull a disk that is still mounted.

Common options

OptionWhat it does
umount /dataBy mount point.
umount /dev/xvdf1By device.
-lLazy.
-fForce (NFS).
fuser -vm /dataWho is using it.

How to do it (step by step)

  1. Try to unmount.
sudo umount /data

Output:

umount: /data: target is busy.

What it means: Something is still inside.

  1. Find who.
sudo fuser -vm /data

Output:

                     USER        PID ACCESS COMMAND
/data:               ravi       3301 ..c.. bash

What it means: Your own shell sits in /data.

  1. Leave and retry.
cd ~ && sudo umount /data && echo done

Output:

done

What it means: Unmounted cleanly.

  1. Stale NFS.
sudo umount -f -l /mnt/nfs

What it means: Detached even though the NFS server is gone.

Practise this in the tasks below: Practice tasks

Real use: A Hadapsar media house unmounts its edit-suite disks with umount before the courier takes them to the client.

25. uname: Show kernel and system info

uname in depth: kernel and machine info

Why do we need this?

Is this server ARM or x86? Which kernel is running after the patch? Which binary should you download? uname answers.

What is it?

uname prints system info: -s kernel name, -r kernel release, -m machine hardware (x86_64, aarch64), -n hostname, -a everything. /etc/os-release tells the distribution, which uname does not.

Common options

OptionWhat it does
-aAll.
-rKernel release.
-mArchitecture.
-nHostname.
-sKernel name.

How to do it (step by step)

  1. Everything.
uname -a

Output:

Linux web01 6.1.112-122.189.amzn2023.x86_64 #1 SMP x86_64 GNU/Linux

What it means: Amazon Linux 2023 kernel on x86_64.

  1. After patching.
uname -r

Output:

6.1.115-126.197.amzn2023.x86_64

What it means: New kernel is running.

  1. Right download.
uname -m

Output:

aarch64

What it means: Graviton: get the arm64 build.

  1. Distribution.
grep PRETTY /etc/os-release

Output:

PRETTY_NAME="Amazon Linux 2023.6.20241010"

What it means: uname does not show this.

Practise this in the tasks below: Practice tasks

Real use: A Baner IoT company checks uname -m in its installer so the same script works on Raspberry Pi and x86 gateways.

26. Commands in this range already covered in depth

Why do we need this?

These commands already have a full why, what and how section in an earlier chapter. Repeating them here would only make the page longer.

What is it?

Each link opens the exact section with options, examples and output.

How to do it (step by step)

  • touch: Create empty files and change timestamps: -a, -m, -d and -r

27. Real examples from many industries

Why do we need this?

The same Linux skill shows up in every kind of company. Seeing it in many places helps you remember it.

What is it?

Each row is a made-up team. It shows who uses this and how.

How to do it (step by step)

Team and cityHow they use itCommand
Kiran, payments, HinjewadiTraces missing filesstrace -e trace=openat ./app
Swati, hospital IT, ShivajinagarWatches PACS logstail -F pacs.log
Amit, e-commerce, HadapsarRestarts servicessystemctl restart api
Priya, SaaS, KharadiRuns migrations in tmuxtmux new -s migrate
Rohan, CA office, DeccanWeekly backupstar czf clients.tgz /srv/clients
Anjali, OTT, YerawadaRaises file limitsLimitNOFILE=65535

28. Common errors and how to fix them

Why do we need this?

Everyone hits these errors. Knowing the cause saves hours.

What is it?

Read the exact message first. Then match it to a row below.

How to do it (step by step)

Error you seeWhy it happensHow to fix
strace: attach: ptrace(PTRACE_SEIZE, 4120): Operation not permittedNot root or ptrace blockedRun with sudo.
sudo strace -p 4120
su: Authentication failureWrong target password or root has noneUse sudo su - or sudo -i.
sudo -i
ravi is not in the sudoers file. This incident will be reported.No sudo rightsAsk an admin to add you to wheel.
sudo usermod -aG wheel ravi
swapon: /swapfile: insecure permissions 0644, 0600 suggested.Swap file readable by otherschmod 600 it.
sudo chmod 600 /swapfile
sysctl: cannot stat /proc/sys/net/ipv4/ip_fwd: No such file or directoryWrong parameter nameSearch the real name.
sysctl -a | grep forward
Job for nginx.service failed because the control process exited with error code.Service failed to startRead the journal.
journalctl -u nginx -n 30
tail: inotify cannot be used, reverting to pollingToo many inotify watchesRaise max_user_watches.
sudo sysctl -w fs.inotify.max_user_watches=524288
tar: Exiting with failure status due to previous errorsSome files unreadableRead the earlier lines; run with sudo.
sudo tar czf b.tgz /etc
tee: /etc/hosts: Permission deniedtee ran as youPut sudo before tee.
echo x | sudo tee -a /etc/hosts
[: too many argumentsUnquoted variable with spacesQuote the variable.
[ -z "$name" ]
umount: /data: target is busy.Process using the mountFind and stop it.
fuser -vm /data
sessions should be nested with care, unset $TMUX to forceAlready inside tmuxDetach or use a new window.
tmux detach

29. Troubleshooting step by step

Why do we need this?

When a Part 7 command does not do what you expect, go through these steps.

What is it?

Go top to bottom. Stop at the first step that shows the problem.

How to do it (step by step)

  1. Are you the right user?
whoami; sudo -l
  1. Is the service running?
systemctl status app
  1. What did it log?
journalctl -u app -n 30
  1. What does it touch?
sudo strace -f -e trace=file -p PID
  1. Limits and kernel?
ulimit -a; sysctl -a | grep somaxconn
  1. Disk or mount busy?
df -h; fuser -vm /data

30. Lab 1: Make a service, break it and fix it

Why do we need this?

Create a small systemd service, find why it fails with tail and strace, fix it and verify.

What is it?

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

How to do it (step by step)

  1. Write a script.
printf "#!/bin/bash\nwhile true; do cat /etc/lab.conf; sleep 5; done\n" | sudo tee /usr/local/bin/lab.sh > /dev/null; sudo chmod +x /usr/local/bin/lab.sh
  1. Create the unit.
printf "[Service]\nExecStart=/usr/local/bin/lab.sh\n" | sudo tee /etc/systemd/system/lab.service > /dev/null; sudo systemctl daemon-reload; sudo systemctl start lab
  1. See the error.
journalctl -u lab -n 2 --no-pager

Output:

cat: /etc/lab.conf: No such file or directory
  1. Fix and watch.
echo "mode=ok" | sudo tee /etc/lab.conf; journalctl -u lab -n 1 --no-pager

Output:

mode=ok
  1. Clean up.
sudo systemctl stop lab; sudo rm /etc/systemd/system/lab.service /usr/local/bin/lab.sh /etc/lab.conf; sudo systemctl daemon-reload

31. Lab 2: Back up, time and guard a folder

Why do we need this?

Write a backup that checks conditions, times itself, logs with tee and runs in tmux.

What is it?

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

How to do it (step by step)

  1. Start tmux.
tmux new -s backup
  1. Guard.
[ -d /etc ] && [ "$(df --output=pcent /tmp | tail -1 | tr -dc 0-9)" -lt 90 ] && echo ok

Output:

ok
  1. Back up and time it.
time sudo tar czf /tmp/etc.tgz /etc 2>&1 | tee /tmp/backup.log

Output:

real    0m1.204s
  1. Verify.
tar tzf /tmp/etc.tgz | wc -l

Output:

1430
  1. Detach and clean.
tmux detach; rm /tmp/etc.tgz /tmp/backup.log

Ravindra Bagale's Tip

When something fails, read before you change: systemctl status, then tail the log, then strace. Change one thing at a time and note it with tee, so you can undo it.

32. Frequently asked questions

Q. su or sudo?

sudo: your own password, logged, limited. su needs the other password.

Q. tmux or screen?

tmux is newer with better panes; screen is everywhere on old systems.

Q. tail -f or -F?

-F keeps following after the log is rotated.

Q. Delete or truncate a full log?

Truncate if a process still writes it; delete does not free space until it closes.

Q. Is strace safe on production?

It slows the process a lot; use it briefly and with -e filters.

Q. which or type?

type knows aliases and functions; which only searches PATH.

33. Interview questions and answers

Beginner level

Q. How do you run one command as root?

sudo command.

Q. How do you see the last lines of a log?

tail -n 50 file.

Q. How do you check a service?

systemctl status name.

Q. How do you see the kernel version?

uname -r.

Mid level level

Q. Write a root-owned file from a pipe.

echo x | sudo tee file.

Q. Enable IP forwarding permanently.

File in /etc/sysctl.d then sysctl --system.

Q. Too many open files in nginx.

LimitNOFILE in a systemd override, restart.

Q. Disk full but rm freed nothing.

A process holds it open: truncate or restart, check lsof +L1.

Senior level

Q. A service fails with no log. Your approach?

status, journalctl -u, run ExecStart by hand as the service user, strace -f -e trace=file.

Q. Load is 12 on 4 CPUs. Next steps?

top for us vs wa, vmstat trend, then the top process or disk.

Q. Design sudo for a support team.

Group in /etc/sudoers.d with only needed commands, edited with visudo, logs reviewed.

Q. Backups must not fill the disk. How?

test the free space first, tar with exclude, time it, tee a log, cron it.

Try at home

  1. Make a 1 GB swap file on a test VM and remove it afterwards.
  2. Write a systemd unit for a tiny script and make it start at boot.
  3. Use strace -c on ls -R / and note the top three system calls.
  4. Back up your home folder with tar, excluding .cache, and list it.

Practice Tasks

About this scenario

Maple Leaf Books is a bookselling business in Toronto. Emily Tremblay looks after its IT and cloud work. They count money in CAD and run their AWS resources in the ca-central-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 24

Easy Become a user

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Switch to the user kavita with a full login shell.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Run as another user

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Run whoami as the user tomcat using sudo.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Restart a service

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Restart the service named redis.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Last lines

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Show the last 25 lines of payroll.log.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Attach session

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Attach to the tmux session named nightly.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Uppercase

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Convert the text from names.txt to uppercase.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Tree depth

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Show the tree of /srv/portal only two levels deep.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Unmount

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Unmount /media/usb7.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Kernel release

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Print only the kernel name.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Trace a running process

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Attach strace to process 7734 and follow its children.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium List sudo rights of a user

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: List the sudo rights of the user deploybot.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Turn on swap

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Enable swap on the file /swapspace2.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Read a kernel value

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Print the value of vm.swappiness.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Disable at boot

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Stop cups from starting at boot and stop it now.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Create xz archive

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Create the archive shop.tar.xz from the folder shopdata using xz.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Extract to folder

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Extract ledger.tgz into the folder /restore2.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Append with tee

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Append the line ok to deploy-history.txt using tee, while also printing it.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Test for a file

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Test whether /etc/fstab.bak exists as a regular file.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Set timezone

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Set the system timezone to Europe/London.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Batch top

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Run top in batch mode for 3 refreshes.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Trace without DNS

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Trace the route to 10.20.0.5 without resolving names.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Empty a log

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Empty gateway.log to zero bytes without deleting it.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Count system calls

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Show a summary count of system calls made by ./importer.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Set a kernel value now

Why: BIZ runs Linux servers and uses commands from strace to uname daily.

What to do: Set net.core.somaxconn to 8192 for the running kernel.

How:
  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

In short

  1. strace, top: see what a process does.
  2. su, sudo: switch user safely.
  3. swapon, sysctl, ulimit, umask: system settings.
  4. systemctl, tail, timedatectl: services, logs and time.
  5. tar, tee, truncate, tree, umount: files and disks.
  6. test, time, tr, type, tmux, traceroute, uname: scripts and tools.

Revision, comparison and interview cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Fix a service in 4 steps. Check state. Read the log. Restart. Start at boot.
Revision card: Fix a service in 4 steps · Download PNG · Open card page
Backups with tar. Create gzip archive. List it. Extract to a folder. Use xz.
Revision card: Backups with tar · Download PNG · Open card page
su vs sudo. Switches to another user. / Runs one command as root.
Comparison: su vs sudo · Download PNG · Open card page
tail vs journalctl. Reads a text log file. / Reads the systemd journal.
Comparison: tail vs journalctl · Download PNG · Open card page
App fails with no clear error?. Trace file calls. Look for ENOENT or EACCES. Attach to a PID.
Interview card: App fails with no clear error? · Download PNG · Open card page
su or sudo for admins?. sudo uses your password. Every command is logged. Edit rules with visudo.
Interview card: su or sudo for admins? · Download PNG · Open card page
Permission denied with sudo echo?. The redirect runs as you. Use sudo tee. Hide the echo.
Interview card: Permission denied with sudo echo? · Download PNG · Open card page
Disk full but rm freed nothing?. A process keeps the file open. Find deleted open files. Truncate instead.
Interview card: Disk full but rm freed nothing? · Download PNG · Open card page

More cards: Ravi Sir's Cards.