System
Notes target Debian and Ubuntu. Other distributions differ, mainly in the package manager — see Package management.
Version and hardware
lsb_release -a # distribution and release
hostnamectl | grep Kernel
uname -mrs # kernel name, release, machine
nproc # number of available cores
egrep '(vmx|svm)' /proc/cpuinfo # CPU supports hardware virtualization
Ubuntu 22.04 notable changes
- Wayland is the default display server for most users.
- Linux kernel 5.15, GNOME 42.
- PHP 8.1, Ruby 3.0, Python 3.10, OpenJDK 18.
nftablesis the default firewall backend, replacingiptables.- Firefox ships only as a Snap package.
- RDP replaces VNC as the default remote desktop protocol.
scpnow supports the SFTP transfer mode.- BIND 9.18 supports DNS over TLS/HTTPS and zone transfers over TLS.
Reboot and shutdown
sudo reboot -h 0 # reboot immediately
poweroff
halt
systemd services
# Status and logs
systemctl status SERVICE
journalctl -u SERVICE -b # this boot
journalctl -u app.service -b
# Start a templated service with an argument
systemctl start 'autontfsfix@arg1 arg2.service'
# Enable / disable
systemctl enable SERVICE
systemctl disable SERVICE
# Remove a service completely
systemctl stop SERVICE
systemctl disable SERVICE
rm /etc/systemd/system/SERVICE
rm /usr/lib/systemd/system/SERVICE
systemctl daemon-reload
systemctl reset-failed
systemd-oomd can kill a user session and drop you to the login screen. To
disable it:
sudo systemctl disable --now systemd-oomd
sudo systemctl mask systemd-oomd
# Re-enable
sudo systemctl unmask systemd-oomd
systemctl enable systemd-oomd
Environment variables
VAR1="var1" # local: child shells cannot see it
export VAR2="var2" # exported: inherited by child processes
export # list exported variables in this session
Timezone
# Debian / Ubuntu: reconfigure tzdata rather than editing files by hand
sudo dpkg-reconfigure tzdata
date # verify
Disable the screen lock
gsettings set org.gnome.desktop.lockdown disable-lock-screen true
Logs
/var/log/auth.log # authentication / login
tail -f /var/log/syslog | grep CRON # follow cron activity
screen
A terminal multiplexer that keeps sessions alive after disconnect.
screen -version
screen -S SESSION_NAME # start a named session
echo $STY # non-empty when inside screen
screen -ls # list sessions
screen -r # reattach (single session)
screen -r 1164 # reattach by id
screen -x pts-1.localhost # attach to an already-attached session
# Detach: Ctrl-A then D
sudo screen -X -S 1164 quit # kill a session
# Start a detached session, e.g. from crontab
/usr/bin/screen -dmS nomp /bin/bash -c 'nvm use v0.10.48; cd ~/nomp; node init.js; exec /bin/bash'
crontab
Changes take effect without a restart. Each user (including root) has a separate crontab.
crontab -e # edit the current user's crontab
sudo crontab -e # edit root's crontab
# ┌───────────── minute (0 - 59)
# │ ┌─────────── hour (0 - 23)
# │ │ ┌───────── day of month (1 - 31)
# │ │ │ ┌─────── month (1 - 12)
# │ │ │ │ ┌───── day of week (0 - 7, 0 is Sunday, 6 is Saturday, 7 is also Sunday)
# │ │ │ │ │
# * * * * * /path/to/command
*/10 * * * * /bin/do # every 10 minutes
0 3 * * 1,3,5 truncate -s 0 /root/.forever/*.log # 03:00 on Mon/Wed/Fri
0 0 1 */2 * /usr/bin/certbot renew --quiet --no-self-upgrade --nginx
Special shorthands:
| Shorthand | Equivalent |
|---|---|
@reboot | Once after every reboot |
@yearly / @annually | 0 0 1 1 * |
@monthly | 0 0 1 * * |
@weekly | 0 0 * * 0 |
@daily | 0 0 * * * |
@hourly | 0 * * * * |
Benchmark
time ./script.sh # wall-clock time of a command
# Geekbench
mkdir geekbench && cd geekbench
wget https://cdn.geekbench.com/Geekbench-5.4.4-Linux.tar.gz
tar -xzvf Geekbench-5.4.4-Linux.tar.gz
cd Geekbench-5.4.4-Linux
./geekbench5