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.
Common operations for working with files, directories, and compressed archives.
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 -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)
Tools for searching, transforming, and inspecting text files and command output. These are most useful when composed with pipes.
Grep:grep "pattern" file.txtgrep -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.txtsed -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.csvcut -c1-10 file.txt
(-d delimiter, -f fields, -c character positions)
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.txtls | 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.txttail -n 10 file.txttail -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)
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 {}")
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
Diff:diff file1.txt file2.txtdiff -u file1.txt file2.txt
(-u unified format, easier to read; used by git diff)
systemd is the init system and service manager on most modern
Linux distributions. systemctl manages units (services,
timers, sockets); journalctl reads the unified log.
sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx # reload config without full restart
sudo systemctl enable nginx # start on boot
sudo systemctl disable nginx # don't start on boot
sudo systemctl enable --now nginx # enable + start immediately
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 -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
[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)
Tools for managing network connections and monitoring traffic.
nmcli device wifi list
nmcli device wifi connect "SSID" password "PASSWORD" ifname wlp2s0
Set display brightness (xrandr):xrandr --output HDMI-1 --brightness 0.8xrandr --output eDP-1 --brightness 0.8
Common administration tasks for managing services, permissions, and audio on Linux.
pactl list sinks short # list available sinks
pactl set-default-sink <sink_id> # set default
sudo ln -s /var/lib/flatpak/exports/bin/com.stremio.Stremio /usr/bin/stremio
sudo chown -R www-data:www-data /var/www/example/
sudo chmod -R 755 /var/www/example/
Download audio and video from YouTube and other sites.
Add --cookies-from-browser BROWSER if the site
requires authentication.
yt-dlp --restrict-filenames \
-P "~/Downloads/YouTube" \
-o "%(title)s-%(id)s.%(ext)s" \
-f "bestaudio" -x \
--no-playlist --audio-format opus \
<URL>
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>
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>