Linux: Ubuntu cheat sheet

Robert Andresen PC and apps Leave a Comment

This a personal Cheat sheet for Ubuntu (mostly server related stuff) + some MySQL and Docker commands. This page will be updated when I find useful commands 🙂



Show filsystem disk usage

df -h

Find what taking up diskspace

du -cha --max-depth=1 / | grep -E "M|G"


Import / export mysql database

# Export
mysqldump -u username -p databasename > filename.sql

# Import
mysql -u username -p databasename < filename.sql


Auto-start / restart docker-container

docker update --restart=always 0576df221c0b

# More "gentle" mode from the documentation:
docker run -dit --restart unless-stopped <image_name>

# Stop all running containers
docker stop $(docker ps -aq)



# Deploy new version
kubectl rollout restart deployment/myapp-deployment

# Get pods (-o wide for more info)
kubectl get pod -o wide

# Bash inside pod
kubectl exec --stdin --tty myapp-1234-abcd -- /bin/bash

# Logs from pod (-f for follow)
kubectl logs -f myapp-1234-abcd


List installed PHP-extentions

sudo dpkg --list | grep php
# OR dpkg --get-selections | grep -i php
# OR php -m
# OR php -m | grep -i ftp

Check for avalible PHP-extentions

apt-cache search php | grep "^php7"
# OR apt-cache search php | grep "^php"


Read log-file backwards:

tac filename | less

Check ssh login:

#Check for failed login
grep sshd.\*Failed /var/log/auth.log | less

# Check for accepted login
grep sshd.\*Accepted /var/log/auth.log | less



#3009 - Column count of mysql.user is wrong. Expected 51, found 49. Created with MySQL 80012, now running 80015. Please use mysql_upgrade to fix this error.

mysql_upgrade --force -uroot -p

Full /boot


sudo dpkg --list 'linux-image*'|awk '{ if ($1=="ii") print $2}'|grep -v `uname -r`

sudo rm -rf /boot/*-3.19.0-{25,56,58,59,61,65}-*

sudo apt-get -f install

sudo apt-get autoremove

sudo update-grub

sudo apt-get update