Info
Content

Cheat Sheet

Debian

Format partition

mkfs.ext4 /dev/sdX

Set disk sleep timer

hdparm -S n /dev/sdb
# every n is 5 seconds
hdparm -S 60 /dev/sdb #timeout 5 min

Recursively chown all files that are owned by a specific user source

You can use this portable find command with something like this.

find . -user old-user -exec chown new-user:new-group {} \;

You can expand this to find specific files with -iname options (non POSIX but available on OSX)

find . -iname '*.html' -user www-data -exec chown www-data:www-data {} \;

The . stands for the current folder and below, so you could use a specific path as a base.

find /var/www/ -iname '*.html' -user www-data -exec chown www-data:www-data {} \;

LVM

#Extend disk
lvextend -L+1G /dev/pve/vol #add 1GB
resize2fs /dev/pve/vol

Proxmox bind mount

Remember: Do not add comments in container config file

Read only

mp0: /HOST/PATH/,mp=/CONTAINER/PATH/,ro=1

If container is unprivileged then add 100000 to UID and GID (root is 100000 and www-data is 100033)

Read and write

mp0: /HOST/PATH/,mp=/CONTAINER/PATH/
mp1: /HOST/PATH1/,mp=/CONTAINER/PATH1/
mp2: /HOST/PATH2/,mp=/CONTAINER/PATH2/

Automatically mount disk by UUID

Get the UUID of the disk

blkid

Edit /etc/fstab and add

Note: This config will hang booting until the disk is found and mounted

UUID=874b3e03-d48f-xxxx-xxxx-xxxxxxxxxxxx /MOUNT/PATH/ ext4 errors=remount-ro 0 2

List all user

cat /etc/passwd

Proxmox enter container w/o password

pct enter <CTID>

Get CPU usage %

grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage "%"}'

Get CPU temp °C

Install lm-sensors

sudo apt-get install lm-sensors

After installation type the following in terminal

sudo sensors-detect

Show temp per core

sensors

Get load average

Load average last 1 min, 5 min, 15 min

get something like 17:56:38 up 1 day, 18:45, 1 user, load average: 0.31, 0.40, 0.50

uptime

Empty file (e.g. log file)

Empty file without changing permission or ownership

: > /var/log/messages

Run command as another user

su - <username> -c <command>

Show all folder and file size

#-a show all files/folders
#-h human readable
#-s non recursive
#-c show total

#Size of every file - human readable
du -ah

#Size of every element non recursive - human readable
du -sh * 

#Size of the current folder - human readable
du -sh

#same as -sh but show also the total size
du -sch

Show all disk usage and disk free space

df -h
#-h human readable

MySQL/MariaDB

Export all DBs to mydatabases.sql

mysqldump -u root -p --all-databases > mydatabases.sql

Import all DBs from mydatabases.sql

mysql -u root -p < mydatabases.sql

 

 

No Comments
Back to top