๐Ÿง Linux

โ† Back to Cheatsheets

Command-line utilities and Linux system administration. Covers file operations, text processing, systemd service management, networking, and useful tools for daily operations. For scripting and shell syntax, see the Bash cheatsheet.

Platform: GNU/Linux (most examples tested on Fedora) Shell: bash / POSIX sh Package managers: dnf ยท apt ยท pacman
Resources: man7.org โ€” Linux man pages tldr pages โ€” simplified man pages explainshell.com systemd.io yt-dlp docs

Files & Archives

โ–ผ

Common operations for working with files, directories, and compressed archives.

Tar โ€” extract / create
tar -xzvf archive.tar.gz          # extract
tar -czvf archive.tar.gz dir/     # create
tar -tzvf archive.tar.gz          # list contents
(-x extract, -c create, -z gzip, -v verbose, -f file)
Zip / Unzip
zip -r archive.zip directory/
zip archive.zip *
unzip archive.zip -d output_dir/
Find files
find /home/user -name "*.zip"
find . -type f -mtime -7
(-type f = files only; -mtime -7 = modified in last 7 days)
Symlink
ln -s /path/to/target /path/to/link
(e.g. to expose a Flatpak app to dmenu/rofi)

Text Processing

โ–ผ

Tools for searching, transforming, and inspecting text files and command output. These are most useful when composed with pipes.

Grep
grep "pattern" file.txt
grep -r "pattern" ./dir
(-i case-insensitive, -n show line numbers, -l filenames only, -v invert match)
Sed โ€” find & replace
sed 's/old/new/g' file.txt
sed -i 's/old/new/g' file.txt
(-i edits in place; omit to preview)
Awk โ€” print column
ls -l | awk '{print $9}'
awk -F: '{print $1}' /etc/passwd
($NF = last column; -F sets field separator)
Cut โ€” extract columns
cut -d',' -f1,3 file.csv
cut -c1-10 file.txt
(-d delimiter, -f fields, -c character positions)
Sort & Uniq
sort file.txt                  # sort alphabetically
sort -n file.txt               # sort numerically
sort -rn file.txt              # reverse numeric sort
sort file.txt | uniq           # remove duplicate lines
sort file.txt | uniq -c        # count occurrences
sort file.txt | uniq -d        # show only duplicates
Wc โ€” count lines / words / chars
wc -l file.txt
ls | wc -l
(-l lines, -w words, -c bytes)
Tr โ€” translate / delete characters
echo "hello" | tr 'a-z' 'A-Z'
echo "a::b::c" | tr -s ':' ','
(-s squeezes repeated characters, -d deletes)
Head / Tail
head -n 10 file.txt
tail -n 10 file.txt
tail -f app.log
(-f follows the file live; useful for logs)
Less
less large_file.log
(/ to search, n/N to navigate matches, q to quit)
Diff
diff file1.txt file2.txt
diff -u file1.txt file2.txt
(-u unified format, easier to read; used by git diff)
Xargs โ€” build commands from stdin
find . -name "*.log" | xargs rm
find . -name "*.txt" | xargs grep "error"
cat urls.txt | xargs -n1 curl -O    # -n1 = one arg per call
(use -I{} for inline substitution: echo "world" | xargs -I{} echo "hello {}")
Pipe & redirect
ls -l | grep ".zip"           # pipe stdout to grep
ls > file_list.txt            # redirect stdout (overwrite)
echo "new line" >> file.txt   # redirect stdout (append)
command 2>&1 | tee out.log    # stderr to stdout, tee to file + screen

systemd

โ–ผ

systemd is the init system and service manager on most modern Linux distributions. systemctl manages units (services, timers, sockets); journalctl reads the unified log.

Service lifecycle
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx      # reload config without full restart
Enable / disable on boot
sudo systemctl enable nginx      # start on boot
sudo systemctl disable nginx     # don't start on boot
sudo systemctl enable --now nginx  # enable + start immediately
Status and inspection
systemctl status nginx
systemctl is-active nginx        # exits 0 if active
systemctl is-enabled nginx
systemctl list-units --type=service --state=running
Reload unit files after editing
sudo systemctl daemon-reload
(required after creating or modifying a .service file)
journalctl โ€” view logs
journalctl -u nginx              # logs for a specific unit
journalctl -u nginx -f           # follow live
journalctl -u nginx --since "1 hour ago"
journalctl -u nginx -n 50        # last 50 lines
journalctl -p err                # errors only (emerg alert crit err warning notice info debug)
journalctl --disk-usage          # how much space logs use
Minimal unit file example
[Unit]
Description=My App
After=network.target

[Service]
ExecStart=/usr/bin/myapp --config /etc/myapp.conf
Restart=on-failure
User=myuser

[Install]
WantedBy=multi-user.target
(place in /etc/systemd/system/myapp.service, then daemon-reload + enable)

Networking

โ–ผ

Tools for managing network connections and monitoring traffic.

Connect to WiFi (nmcli)
nmcli device wifi list
nmcli device wifi connect "SSID" password "PASSWORD" ifname wlp2s0
Set display brightness (xrandr)
xrandr --output HDMI-1 --brightness 0.8
xrandr --output eDP-1 --brightness 0.8

System Administration

โ–ผ

Common administration tasks for managing services, permissions, and audio on Linux.

PipeWire โ€” set default audio output (Fedora)
pactl list sinks short              # list available sinks
pactl set-default-sink <sink_id>   # set default
NGINX โ€” fix file permissions
sudo chown -R www-data:www-data /var/www/example/
sudo chmod -R 755 /var/www/example/
Expose Flatpak app to PATH (e.g. for dmenu/rofi)
sudo ln -s /var/lib/flatpak/exports/bin/com.stremio.Stremio /usr/bin/stremio

yt-dlp

โ–ผ

Download audio and video from YouTube and other sites. Add --cookies-from-browser BROWSER if the site requires authentication.

Best audio quality (Opus)
yt-dlp --restrict-filenames \
    -P "~/Downloads/YouTube" \
    -o "%(title)s-%(id)s.%(ext)s" \
    -f "bestaudio" -x \
    --no-playlist --audio-format opus \
    <URL>
Specific quality video + audio (1080p WebM)
yt-dlp --restrict-filenames \
    -P "~/Downloads/YouTube" \
    -o "%(title)s-%(height)sp-%(id)s.%(ext)s" \
    -f "bestvideo[height=1080]+bestaudio" \
    --no-playlist --merge-output-format webm \
    <URL>
Best video + audio quality (WebM)
yt-dlp --restrict-filenames \
    -P "~/Downloads/YouTube" \
    -o "%(title)s-%(height)sp-%(id)s.%(ext)s" \
    -f "bestvideo+bestaudio" \
    --no-playlist --merge-output-format webm \
    <URL>