Files and directories#
ls -lah # long listing incl. hidden files, human sizes
cp -a src/ dest/ # copy preserving attributes
mv old new # move or rename
rm -r dir/ # remove a directory recursively
mkdir -p a/b/c # create nested directories
find . -name "*.log" -mtime +7 # .log files older than 7 days
du -sh * # size of each item here
Permissions#
| Command |
Effect |
chmod 644 file |
Owner read/write, others read |
chmod 755 script.sh |
Owner all, others read/execute |
chmod u+x script.sh |
Add execute for owner |
chown user:group file |
Change owner and group |
sudo -u www-data cmd |
Run a command as another user |
Processes#
ps aux --sort=-%mem | head # top memory consumers
top # live view (or htop)
pgrep -fa nginx # find processes by name
kill -TERM <pid> # ask a process to stop
kill -9 <pid> # force kill (last resort)
Services (systemd)#
systemctl status nginx
sudo systemctl restart nginx
sudo systemctl enable --now nginx # start now and at boot
journalctl -u nginx -f # follow a unit's logs
journalctl --since "1 hour ago"
Disks#
df -h # free space per filesystem
lsblk # block devices
mount | column -t
Networking#
ip -br addr # interfaces and addresses
ss -tulpn # listening ports and owning processes
curl -I https://example.com
dig +short example.com
Packages#
| Distro |
Update |
Install |
| Debian/Ubuntu |
sudo apt update && sudo apt upgrade |
sudo apt install pkg |
| Fedora/RHEL |
sudo dnf upgrade |
sudo dnf install pkg |
| Arch |
sudo pacman -Syu |
sudo pacman -S pkg |
| Alpine |
apk update && apk upgrade |
apk add pkg |