# Service management
systemctl start <service>
systemctl stop <service>
systemctl restart <service>
systemctl reload <service>
systemctl enable <service>
systemctl disable <service>
systemctl status <service>
# View logs
journalctl -u <service>
journalctl -u <service> -f # follow
journalctl -u <service> --since "1 hour ago"
# List units
systemctl list-units --type=service
systemctl list-units --state=failed
# Variables
VAR="value"
echo $VAR
echo ${VAR:-default} # use default if unset
# Conditionals
if [ -f /path/to/file ]; then
echo "file exists"
fi
if [ "$VAR" = "value" ]; then
echo "match"
fi
# Loops
for i in 1 2 3; do echo $i; done
for f in /etc/*.conf; do echo $f; done
while read line; do
echo "$line"
done < file.txt
# Functions
myfunc() {
local arg1="$1"
echo "arg: $arg1"
}
# Redirect both stdout and stderr
command > output.log 2>&1
# Background job
command &
wait # wait for all background jobs