Bart Simons

cheat sheet

A 3 post collection

Ubuntu Cheat Sheet

 •  Filed under ubuntu, cheat sheet

In need of a handy cheat sheet filled with commands you can use in your Linux terminal? This page has got you covered with lots of commands for lots on different use cases. Missing a command? Feel free to send me your ideas, questions and suggested commands in the comments.

Install a full LAMP stack with just one command
sudo apt install lamp-server^  

Notes: this stack contains PHP5 on Ubuntu 14.04 or lower, and PHP7 on Ubuntu 16.04 or higher. Not tested with non-LTS releases.

Install PhpMyAdmin
sudo apt install phpmyadmin  

Install and configure basic SMB/CIFS shared folder
sudo apt install samba  
sudo smbpasswd -a bart

sudo echo "[bart]" >> /etc/samba/smb.conf  
sudo echo "path = /home/bart" >> /etc/samba/smb.conf  
sudo echo "valid users = bart" >> /etc/samba/smb.conf  
sudo echo "read only = no" >> /etc/samba/smb.conf

sudo service smbd restart  

Install security updates only
sudo unattended-upgrades -d  

Upgrade to the next LTS release
sudo do-release-upgrade  

Cleanup the package database and no longer needed packages
sudo apt autoremove && sudo apt clean && sudo apt autoclean  

List kernel version and Ubuntu release version
uname -a && lsb_release -a  

Edit and update grub settings
sudo nano /etc/default/grub  

Get unique IPs accessing your site

For Apache:

cat /var/log/apache2/access.log | awk '{print $1}' | sort -u  


cat /var/log/nginx/access.log | awk '{print $1}' | sort -u  

Use Ubuntu as a NAT router
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf  
sysctl -p  

Get bash history
cat ~/.bash_history  

Get SSH login attempts that exceed set limits
cat /var/log/auth.log | grep "attempts"  

Get successful local and remote login attempts
cat /var/log/auth.log | grep "systemd-logind"  

Check for open, listening ports
netstat -tulpn  

Get RAM usage information
free -m  

Get processes currently running as root
ps aux | grep "root"  

Stop and start interface
ifconfig eth0 down  
ifconfig eth0 up  

Note: replace eth0 with your desired network interface.

Manually set static IP on interface
ifconfig eth0 netmask broadcast  

Check for running systemd services
systemctl list-units --state=running --type=service  

Check for configuration errors
jounalctl -xe  

Get cron jobs

Hourly cron jobs:

ls /etc/cron.hourly  

Daily cron jobs:

ls /etc/cron.daily  

Weekly cron jobs:

ls /etc/cron.weekly  

Monthly cron jobs:

ls /etc/cron.monthly  

Other cron jobs:

ls /etc/cron.d  

Hardware/software info

List PCI devices:


List block devices:


List USB devices:


List CPU devices


List general HW info


List loaded kernel modules


File/directory creation, parsing and IO

Create new file

touch new.file  

Get contents of file

cat new.file  

Overwrite a file

echo "Hello, dear Linux user!" > new.file  

Append to a file

echo "Hello, dear Linux user!" >> new.file  

Get lines containing a substring

cat new.file | grep "user"  


Set ownership of a folder, recursively:

chown -R www-data:www-data /var/www/html  

Note: this sets the ownership of the /var/www/html folder to the default web server user and group.

DISM, ImageX and Diskpart Cheat Sheet

 •  Filed under cheat sheet, dism, imagex, diskpart

This page contains ImageX, DISM and Diskpart commands for the development and deployment of WIM disk images.

Obtaining WIM image information

dism /get-wiminfo /wimfile:"yourwimfilegoeshere.wim"

Removing an index from a WIM image

imagex /delete "yourwimfilegoeshere.wim" indexnumbergoeshere

Merge a WIM file with another WIM file

imagex /export "C:\source\install.wim" 1 "C:\destination\install.wim"

Mounting a WIM image

dism /mount-image /imagefile:"yourwimfilegoeshere.wim" /index:indexnumbergoeshere /mountdir:"mountdirgoeshere"

Commit changes and unmount a WIM image

dism /unmount-wim /mountdir:"mountdirgoeshere" /commit

Discard changes and unmount a WIM image

dism /unmount-wim /mountdir:"mountdirgoeshere" /discard

Clean up left over files on the local machine

dism /cleanup-wim

Capture disk files to an image

dism /capture-image /imagefile:diskimage.wim /capturedir:Z:\ /name:"TestImage"

Deploy an image to a disk

imagex /apply "wimfilegoeshere.wim" 1 Z:\

New machine disk partitioning (BIOS)

list disk  
select disk disknumberyouwanttomodify  
convert mbr  
create partition primary  
select partition 1  
format fs=ntfs label=SystemPartition quick  
assign letter=Z  
New machine disk partitioning (UEFI/EFI)

list disk  
select disk disknumberyouwanttomodify  
convert gpt  
create partition efi size=200  
assign letter=s  
format quick fs=FAT32  
create partition primary  
format fs=ntfs label=SystemPartition quick  
assign letter=Z  
Install bootloader in BIOS mode

bcdboot Z:\Windows

Install bootloader in UEFI/EFI mode

bcdboot Z:\Windows /s S: /f UEFI

LXD cheat sheet for beginners

 •  Filed under lxd, cheat sheet, lxc, commands

This page contains a list of handy LXD commands for beginners to get started with LXD. Every command in this guide has been tested on an Ubuntu 16.04 machine.

Configuring a new LXD installation for the first time

sudo lxd init

This command does the following things for you:

  • Setting up the storage backend (zfs or dir)
  • Enabling the RESTful API over the network (or not)
  • Setting up a network bridge for LXD (or not)
  • Setting up NAT for the network bridge (or not)

Checking LXD version

sudo lxd --version

Listing all image servers

sudo lxc remote list

This will output a list of all currently installed image servers

Getting a list of available images from an image server

sudo lxc image list images:

This command fetches a list of all available images from the images image server. You could replace the image server with a different image server. For example, this is what you do to get a list of images from the Ubuntu Daily image server

sudo lxc image list ubuntu-daily:

Getting a filtered image list from an image server

sudo lxc image list images: arm64

This will fetch a list of ARM64 images from an image server.

sudo lxc image list images: arm64 ubuntu

This will fetch a list of ARM64 Ubuntu images from an image server.

Creating a new container

sudo lxc init images:ubuntu/yakkety/amd64 ubuntu-test-1

This command will create a new container called ubuntu-test-1 based on a Ubuntu Yakkety Yak AMD64 image. The image will be fetched from the images image server.

Starting a container

sudo lxc start ubuntu-list-1

This will start the container named ubuntu-list-1

Stopping a container

sudo lxc stop ubuntu-list-1

This will stop the container named ubuntu-list-1

Removing a container

sudo lxc delete ubuntu-list-1

You can force this command with --force if needed.

Listing all containers

sudo lxc list --format table

You can also use json instead of table.

Listing all cached images

sudo lxc image list

Removing a cached image

sudo lxc image delete 4117cf6a0442

This will delete an image with fingerprint ID 4117cf6a0442. You can obtain the fingerprint ID of an image with the sudo lxc image list command.

Executing a command on a container

sudo lxc exec ubuntu-test-1 ping

This will execute the ping executable on the ubuntu-test-1 container.

Getting shell access on a container

You can also use the previous command to execute a shell, for example bash.