App-Cheats

 view release on metacpan or  search on metacpan

cheats.txt  view on Meta::CPAN

kubectl get pods --namespace iam-ns

# Docker Kubernetes - Namespaces
# Check the logs for errors:
kubectl logs --namespace iam-ns pods/keycloak-deployment-PRESS_TAB

# View metrics (kubectl).
minikube addons enable metrics-server
k run myapp --image nginx
k top node
k top pod


#############################################################
## Docker Kubernetes - Roles
#############################################################

# Docker Kubernetes - Roles
# Check for permissions.
auth can-i delete nodes --as dev-user           # no
k auth can-i delete nodes                       # yes


#############################################################
## DOM
#############################################################

# DOM - Update the text of an iframe.
document.querySelector('iframe').contentDocument.querySelector('body').innerText += '\n' + text;

# DOM - Get the html content of an iframe.
document.querySelector('iframe').contentDocument.querySelector('body').innerHTML;
#
# Perl
$Selenium->switch_to_frame(
    $Selenium->find('//iframe')
)
my $HTML = $Selenium->find('//body')->get_attribute('innerHTML');
$Selenium->switch_to_frame()


## E


#############################################################
## FontForge
#############################################################

# FontForge program can update a .ttf file pixmap


#############################################################
## FTP Server/Client
#############################################################

# Create an ftp server on ubuntu.
https://linuxconfig.org/how-to-setup-and-use-ftp-server-in-ubuntu-linux
# 1. Install
sudo apt install vsftpd
#
# 2. backup original /etc/vsftpd.conf
#
# 3. Update /etc/vsftpd.conf
write_enable=YES                 # Dont forget THIS!
local_root=/home/$USER           # Not needed? Works when commented out.
local_umask=002
chroot_local_user=YES
pasv_enable=Yes
pasv_min_port=10000
pasv_max_port=10100
allow_writeable_chroot=YES
#
# 4. Allow ftp through firewall.
#
# 5. Restart ftp daemon.
sudo systemctl restart vsftpd
#
# 6. Create a dedicated ftp user account.
sudo useradd -m ftpuser
sudo passwd ftpuser
#
# 7. Append group to current user
sudo usermod -a -G ftpuser $USER
#
# 8. Apply new group.
sudo su $USER

# Test ftp client on ubuntu.
sudo apt install ftp
ftp
ftp> ftp
192.168.178.48
#
# Not sure about this:
ftp://127.0.0.1/test.html

# Check firewall rules (ubuntu).
sudo ufw status verbose

# Enable firewall (ubuntu).
sudo ufw enable

# A severe vulnerability was published which allows execution of code
# on Linux Systems and Mac OS X systems via network.
# It is rated with a severity of 9.9 out of 10.
# Block port 631 UDP via firewall settings or deinstall cups if not needed.
sudo ufw deny 631/udp

# Allow ftp through firewall.
sudo ufw allow from any to any port 20,21,10000:10100 proto tcp

# Monitor file transfer activity.
sudo tail -f /var/log/vsftpd.log


#############################################################
## GCC
#############################################################

# Compile a c program (-g is for debugging, -o is for a new name)
gcc -g main.c -o new_name

cheats.txt  view on Meta::CPAN

perl -Me -e 'my @a = ( 111, 222 ); say \$a[0]; say \$a[1]; say for map { \$_ } @a; say for \( @a )'
SCALAR(0xb4000073a2e1f678)
SCALAR(0xb4000073a2e1f840)
SCALAR(0xb4000073a2e1f678)
SCALAR(0xb4000073a2e1f840)
SCALAR(0xb4000073a2e1f678)
SCALAR(0xb4000073a2e1f840)

# Process a hash/array with a queue instead of a recursive approach.
# This is documented in:
perldoc -f map
"""
Note that $_ is an alias to the list value, so it can be used to
            modify the elements of the LIST.
"""

# Hash pair slice.
perl -Me -e '%h = ( a => 1, b => 2, c => 3 ); %h2 = %h{qw( a b )}; p \%h; p \%h2'
{
    a => 1,
    b => 2,
    c => 3,
}
{
    a => 1,
    b => 2,
}

# Hash pair slice with delete.
perl -Me -e '%h = ( a => 1, b => 2, c => 3 ); %h2 = delete %h{qw( a b )}; p \%h; p \%h2'
{
    c => 3,
}
{
    a => 1,
    b => 2,
}

# Perl Hash noop.
# There is one additional caveat that didn’t apply to
# square brackets. Since braces are also used for
# several other things (including blocks), you may
# occasionally have to disambiguate braces at the
# beginning of a statement by putting a + or a
# return in front, so that Perl realizes the opening
# brace isn’t starting a block. For example, if you
# want a function to make a new hash and return a
# reference to it, you have these options: 
sub hashem {        { @_ } } # Silently WRONG — returns @_. 
sub hashem {       +{ @_ } } # Ok. 
sub hashem { return { @_ } } # Ok.


#############################################################
## Perl Inplace Edit
#############################################################

# Print attempted change of Shebang line
perl -ple 's{^#!.*$}{#!/usr/bin/perl}' my_file

# Change Shebang line of file (without making a backup)
perl -i -ple 's{^#!.*$}{#!/usr/bin/perl}' my_file

# Change Shebang line of file (and backup the file in the same directory)
perl -i'.bak' -ple 's{^#!.*$}{#!/usr/bin/perl}' my_file

# Change Shebang line of file (and backup the file in another directory)
perl -i'Backup/*.bak' -ple 's{^#!.*$}{#!/usr/bin/perl}' my_file

# Change comment indentation for a file to 60 (some reason need to subtract 1 from the desired amount)
perl -i'.bak' -lpe 's/^(\s*+[^#]+?)\s*(#+.*$)/sprintf "%-59s %s",$1,$2/e' my_file

# Customizable inplace editing (only when desired). Undef disables inplace editing
perl -le 'local $^I = ($run == 1) ? "bak_*" : undef'

# Apply export markings to many files
#
# Goal
sed -i -e '1 e cat export.txt' hpcclr_bore.ada
#
# Only if a single line in files
perl -i -lpe 'INIT{$m=shift; $m=`cat $m`} print "$m"' marking.txt file*
#
# Too long
perl -i -lne 'INIT{$m=`cat marking.txt`} print "$m" if $. == 1; close ARGV if eof; print' file*
#
# Slurps entire file
perl -i -lp0777e 'INIT{$m=`cat marking.txt`} print "$m"' file*
#
# Many system calls
perl -i -0pe 's/^/`cat marking.txt`/e' file1 file2
#
# Cached file content (seems to be like slurp mode)
perl -i -0pe 'INIT{$m=`cat marking.txt`} print $m' file1 file2

# GS2 par.txt into a data structure that can be evaled later
cat par.txt | perl -MData::Dumper -ln00e 'next if /^-/; my($t,@c)=split "\n"; $h{$t}=\@c }{ $d=Data::Dumper->new([\%h]); print $d->Terse(1)->Indent(1)->Deparse(1)->Purity(1)->Sortkeys(1)->Dump' > C


#############################################################
## Perl Math
#############################################################

# solve for 12x + 15y + 16z = 281 (perl,regex)
# maximizing x 
local $_ = 'a' x 281;
my $r    = qr{^ 
 (a*)\1{11}
 (a*)\2{14}
 (a*)\3{15}
$}x;
printf "x=%i y=%i z=%i\n", 
map{length}/$r/;
__END__
x=17 y=3 z=2

# Solve an algebra problem. get all solutions to: 3x + 4y + 5z = 100
perl -lE '("a"x100) =~ /^(a*)\1{2}(a*)\2{3}(a*)\3{4}$(?{ printf "3x+4y+5z=100 (x=%s,y=%s,z=%s)\n", map{length}($1,$2,$3) })(*F)/'

# Solve an algebra problem. get all solutions to: 3x + 4y + 5z = 20
perl -lE '("a"x20) =~ /^(a*)\1{2}(a*)\2{3}(a*)\3{4}$(?{ printf "3x+4y+5z=20 (x=%s,y=%s,z=%s)\n", map{length}($1,$2,$3) })(*F)/'

# View all the permutations of a list (List::Permutor)
perl -le '@a=qw(a b c); @rv=(0..$#a); sub n{@ret=@a[@rv]; @h=@rv; @t=pop @h; push @t,pop @h while @h and $h[-1]>$t[-1]; if(@h){ $x=pop @h; ($p)=grep{$x<$t[$_]}0..$#t; ($x,$t[$p])=($t[$p],$x); @rv=(@h,$x,@t) }else{ @rv=() } @ret} print "@n" while @n=n...

# Find the prime numbers
#

cheats.txt  view on Meta::CPAN


# Perl signal handling (eval,die,__DIE__)
# Capture STDOUT and STDERR.
# Catch die and throw to STDOUT.
perl -MApp::Pod -E '{ local *STDOUT; open STDOUT, ">", \$out or die $!; local *STDERR; open STDERR, ">>", \$err or die $!; print "print-out"; print STDERR "print-err"; local $SIG{__DIE__} = sub{ my $m = shift; chomp $m; print STDERR "<$m>" }; eval{di...
#
# Use $@ to capture eval error.
# Better than SIG{__DIE__} since sub calls may except an die
# to stop something, like Pod::Simple, which is used by Pod::LOL).
perl -Ilib -MApp::Pod -E '{ local *STDOUT; open STDOUT, ">", \$out or die $!; local *STDERR; open STDERR, ">>", \$err or die $!; print "print-out"; print STDERR "print-err"; eval{die "die\n"}; print STDERR "<$@>" if $@; print "print-out2" } say "\n[$...

# Redirect to terminal even when STDOUT and/STDERR are sent somewhere else.
perl -E 'open my $fh, ">", "/dev/tty" or die $!; close *STDOUT; say $fh "111"; say "HERE"; say $fh "123";'
111
123
pod e say

# Perl Signal Handling
# Another  interesting  signal  is  signal  number  0.
# This  doesn’t  actually  affect  the target  process,
# but  instead  checks  that  it’s  alive  and  hasn’t
# changed  its  UIDs. That  is,  it  checks  whether
# it’s  legal  to  send  a  signal,  without  actually
# sending  one. 
unless (kill 0 => $kid_pid) {     
  warn "something wicked happened to $kid_pid"; 
}


#############################################################
## Perl Symbol Table
#############################################################

# Remove a subroutine from the symbol table (perl)
# defined &abs_path will still return 1 since it still exists
# but we removed a reference to it.
delete $Cwd::{'abs_path'}

# Remove the contents of a subroutine (perl)
# defined &abs_path will return 0
# Still found in symbol table
undef $Cwd::{'abs_path'}

# Snippet to capture output in perl.
# Capture output.
my $output = "";
{
    local *STDOUT;
    local *STDERR;
    open STDOUT, ">",  \$output or die $!;
    open STDERR, ">>", \$output or die $!;
    eval { App::Pod->run };
    if ( $@ ) {
        $output = $@;
        chomp $output;
    }
}

# Backup and restore STDOUT in perl.
# Backup current STDOUT
open(my $backup_stdout, '>&', STDOUT) or die "Can't duplicate STDOUT: $!";
# Redirect STDOUT to a file
open(STDOUT, '>', 'output.txt') or die "Can't redirect STDOUT: $!";
# Write to the redirected STDOUT
print "This goes to the output.txt file\n";
# Restore original STDOUT
open(STDOUT, '>&', $backup_stdout) or die "Can't restore STDOUT: $!";

# Give a name to an anonymous sub/function.
# Inside the sub.
# Single global variable.
my $code = sub {
    local *__ANON__ = 'code_name';
    ...
};
$code->();

# Give a name to an anonymous sub/function.
# Outside the sub.
use Sub::Util;
*{"${class}::$_"} = set_subname("${class}::$_", $patch{$_}) for keys %patch;

# Perl typeglob adding a method to an object (symbol table)
perl -E 'package A { sub a{123} } $o = bless {}, "A"; *{(ref $o) . "::b"} = sub{345}; say $o->b'

# Delete a perl function using (typeglob,symbol table)
# It does not seem possible to localize a "delete":
*My::Run = *EMPTY           # Overwrite write an empty symbol table.
delete $A::{a};
delete *{A::}->{a};
delete ${"$pkg\::"}{a};
#
# Instead, just reassign the entire typeglob: (symbol table)
perl -E 'sub Pkg::Func{say 123} $o = bless {}, "Pkg"; {local *Pkg::Func = *Blank; } $o->Func'

# Old school Moose (symbol table, typeglob)
perl -E '
    {
        package ABC;
        sub func{ say "func" }
    }
    {
        my $Orig = \&ABC::func;
        local *ABC::func = sub {
            say "pre";
            $Orig->();
            say "post";
        };
        ABC->func;
    };
    say "\nreverted";
    ABC->func
'

# Moose way to use around (symbol tyble, typeglob)
# DO NOT USE!
# It keeps wrapping the function.
perl -MMoose -E '
    {
        package ABC;
        use Moose;
        sub func{ say "func" }
    }
    {
        Moose::around "ABC", func => sub {
            my ($Orig,$Self,%Param) = @_;
            say "pre";

cheats.txt  view on Meta::CPAN

sys.stdout.flush()


#############################################################
## Python Modules - time
#############################################################

# Seconds since epoch
python -c "import time; print(time.time())"
python -c "import time; print(int(time.time()))"


#############################################################
## Python Modules - watchdog
#############################################################

# Python watchdog has a known bug which triggering 2 on_modified events per change.
import watchdog.observers
https://github.com/gorakhargosh/watchdog/issues/93


#############################################################
## Python Modules - winreg
#############################################################

# Get a subkey from a windows registry key
import winreg
def getLogPath(key,subKey):
    try:
        reg = winreg.OpenKeyEx(winreg.HKEY_LOCAL_MACHINE, key)
        val = winreg.QueryValueEx(reg, subKey)[0]
        return val
    except FileNotFoundError:
        return fallback


## Q


#############################################################
## RSnapshot
#############################################################

# Install rsnapshot
sudo apt install rsnapshot

# Update rsnapshot config
sudo vi /etc/rsnapshot.conf
#
# Make sure to use tab separators
snapshot_root   /media/<USER>/SRTO_BACKUP/BACKUP
no_create_root  1
#
retain  hourly  24
retain  daily   7
retain  weekly  4
retain  monthly 12
#
link_dest       1
#
backup /home/<USER>	timPC
backup /etc			timPC
backup /opt			timPC
backup /root		timPC

# Test rsnapshot configuration file
rsnapshot configtest

# Create crontab for rsnapshot
crontab -e
#
# min hr    dom   mon   dow   command
  0   *     *     *     *     /usr/bin/rsnapshot_runner.pl hourly
  50  23    *     *     *     /usr/bin/rsnapshot_runner.pl daily
  40  23    *     *     6     /usr/bin/rsnapshot_runner.pl weekly
  30  23    1     *     *     /usr/bin/rsnapshot_runner.pl montly

# Rsnapshot example
http://www.edwiget.name/2018/05/simple-rsnapshot-incremental-backups-to-removable-disks/#codesyntax_1


#############################################################
## RTCP (RBS,real time command processor)
#############################################################

# Show rtcp options (DES,DEBHAWK)
rtcp he
rtcp he options
rtcp he op2

# List fbs status
rtcp ls

# Real-time clock device (rtc,DES)
/dev/rrtc/McN
# M - is a controller number (0-3). corresponds to the CPU
# board on which the clock resides
# c - stands for clock
# N - specifies a real-time clock number (0-4 on the first CPU board,
#     and 0-2 on additional CPU boards)

# RTCP Commands (DES)
ats    Attach timing source to an FBS
chs    Change permissions for an FBS
cs     Configure an FBS
dts    Detach timing source from an FBS
rms    Remove an FBS
svs    Save scheduler configuration
vc     View minor cycle/major frame count
vr     View a rdevfs file configuration
vs     View scheduler configuration
rc     Start real-time clock
rd     Register a Coupled FBS device
sc     Stop real-time clock
stc    Set real-time clock values
gtc    Get real-time clock values
start  Start scheduling on an FBS
reg    Register a Closely-Coupled FBS timing device
resume Resume scheduling on an FBS
stop   Stop scheduling on an FBS
rmp    Remove a process from an FBS
rsp    Reschedule a process
sp     Schedule a process on an FBS
unreg  Unregister a Closely-Coupled FBS timing device
urd    Unregister a Coupled FBS device
vp     View processes on an FBS
pm     Start/stop performance monitoring
cpm    Clear performance monitor values
vcm    View or modify performance monitor timing mode
vpm    View performance monitor values
ex     Exit real-time command processor
he     Display help information

# RTCP Options (DES,rtcp he options)
-a               remove program from FBS and terminate
-b {F|R|O}       scheduling policy
-c cpu_bias      cpu bias (* = all CPUs) (default = current CPU)
-d name          devicename or filename
-e               EOC flag

cheats.txt  view on Meta::CPAN

+  'UP',    \
+  'DOWN',  \
+  'LEFT',  \
+  'RIGHT', \
+  'CTRL',  \
+  'ALT',   \
+  'DEL'    \
+  ]]

# Check termux kernel settings.
sudo zcat /proc/config.gz

# Install arm-none-eabi (termux)
git clone git@github.com:poti1/arm-none-eabi.git
cd arm-none-eabi
make

# This variable is set when a new session is created.
# This library intercepts/changes calls to:
# /usr/bin/perl to instead code from the termux folder
echo $LD_PRELOAD
/data/data/com.termux/files/usr/lib/libtermux-exec.so


#############################################################
## Ubuntu - Hard Drive Encryption - Detailed
#############################################################

# Ubuntu hard drive encryption.
# 1. Create the encrypted partition:
sudo cryptsetup luksFormat /dev/sda
#
# Verify header.
sudo cryptsetup luksDump /dev/sda

# Ubuntu hard drive encryption.
# 2. Map the encrypted container:
sudo cryptsetup luksOpen /dev/sda secret-container

# Ubuntu hard drive encryption.
# 2a. Wipe the partition (optional):
sudo shred -vfz /dev/mapper/secret-container

# Ubuntu hard drive encryption.
# 3. Create a filesystem in the mapped container:
sudo mkfs.ext4 /dev/mapper/secret-container

# Ubuntu hard drive encryption.
# SKIP FOR EXTERNAL HARD DRIVES
# 4. Update your /etc/crypttab file (used at system boot):
# Your crypttab should contain a line like
cryptHome     UUID=26a4b17a-aad3-436a-89f4-a68a4c4c371d    none    luks,timeout=30
# with the UUID of the device you just encrypted above
# (i.e. the /dev/sdXX device). You can find it out by using
# e.g. lsblk -f (it should say "crypto_LUKS" under FSTYPE in the output).

# Ubuntu hard drive encryption.
# SKIP FOR EXTERNAL HARD DRIVES
# 5. Update your /etc/fstab file (file system mounting:
# Finally, your fstab should contain a line like
/dev/mapper/cryptHome   /home/srto-backup       ext4    defaults        0       2
#
# to mount the decrypted partition in your filesystem.
# The mapped name (cryptHome) must match the one you
# defined in the crypttab. Replace username by the name of the actual user.
#
# You could also mount it under /home, but then you will have
# all user's home directories in one encrypted drive - that
# means all of them need to know the partition's password to open it on boot.

# Originally thought these were also necessary for an external hard drive.
# Appear to work without the lines.
#
sudo vi /etc/crypttab
# <name>        <device>            <password>      <options>
mnt-usb-crypt   UUID=<device-uuid>  /path/to/key    luks,noauto
#
# Need to run after updating cryptab:
sudo update-initramfs -u -k all
#
sudo vi /etc/fstab
#
# <file system>             <dir>       <type>  <options>                             <dump>    <pass>
/dev/mapper/mnt-usb-crypt   /mnt/usb    btrfs   defaults,noauto,x-systemd.automount   0         2

# Unable to mount the unencrypted harddrive.
# Error mentions mount: wrong fs type, bad option, bad superblock.
#
# See disks:
lsblk
#
# If you can see your drive thats good.
# Run this to see if the system can use it:
sudo fdisk -l
#
# Run this command to attempt to repair bad superblocks on the drive.
sudo xfs_repair /dev/mapper/srto_backup
#
# Mount again after repair is done:
sudo mount /dev/mapper/srto_backup /media/<USER>/SRTO_BACKUP

# Restore corrupted USB drive.
# Warning: could not erase sector 2: Input/output error.
sudo dd if=/dev/zero of=/dev/sdb bs=1M count=40
#
# Disk repair/recovery tool.
sudo apt install testdisk


#############################################################
## Ubuntu - Hard Drive Encryption - Simple
#############################################################

# Ubuntu hard drive encryption. (simple)
#
# Create the encrypted partition:
sudo cryptsetup -c aes-xts-plain -y -s 512 luksFormat /dev/DEVICE
#
# Map the encrypted container:
sudo cryptsetup luksOpen /dev/DEVICE srto_backup
#
# Wipe the partition (optional):
# Only if it has sensitive data already.
sudo shred -vfz /dev/mapper/secret-container
#
# Create a filesystem in the mapped container:
sudo mkfs.ext4 -L MY_BACKUP /dev/mapper/srto_backup
#
# Rename the drive label in gparted (optional)
sudo apt-get install gparted.
# open gparted.
# choose the thumbdrive from the dropdown in the top-right corner.
# unmount the volume (right-click on drive)
# right click and choose "label"
# click on green tick to apply changes.
#
# Find out ID by running
sudo fdisk -l
blkls /dev/<DEVICE>
#
# Or find UUID here for the device
ls -l /dev/disk/by-uuid/
#
# Can find the UUID in gparted.
#
# Add device to be auto decrypted
sudo vi /etc/crypttab
srto_backup UUID=e5dc6e53-2df1-40d8-baff-75ba4f1eacf4 none luks,noauto,size=256
#
# Need to run after updating cryptab:
sudo update-initramfs -u -k all
#
# Add device to be auto mounted
sudo vi /etc/fstab
srto_backup /media/SRTO_BACKUP auto nosuid,nodev,nofail,x-gvfs-show 0 2

# Close encrypted drive
sudo umount /dev/mapper/luks-ea444ab0-445e-4c5c-931b-27922bfa5510
sudo cryptsetup close luks-ea444ab0-445e-4c5c-931b-27922bfa5510
# file found here:
ll /dev/mapper/


#############################################################
## Ubuntu - Hard Drive Create and Delete
#############################################################

# Wipe an external hard drive (with Marco,ubuntu,hd)
#
# Find device here.
lsblk
#
# Remove signature.
sudo wipefs -a /dev/sdb
#
sudo cfdisk /dev/sdb

# Setup a new external hard drive (with Marco,ubuntu,hd)
lsblk    # To find out DEVICE name
sudo cryptsetup -c aes-xts-plain -y -s 512 luksFormat /dev/DEVICE
sudo cryptsetup luksOpen /dev/DEVICE srto_backup
sudo mkfs.ext4 -L MY_BACKUP /dev/mapper/srto_backup
sudo mount /dev/mapper/srto_backup /media/<USER>/SRTO_BACKUP


#############################################################
## Ubuntu - Evolution
#############################################################

# Completely remove ubunutu evolution services.
https://askubuntu.com/questions/315640/how-do-i-completely-remove-evolution
#
cd /usr/share/dbus-1/services
sudo cp org.gnome.evolution.dataserver.* /home/<USER>/my/git/srto/evolution/_usr_share_dbus-1_services/
sudo ln -snf /dev/null org.gnome.evolution.dataserver.Calendar8.service
sudo ln -snf /dev/null org.gnome.evolution.dataserver.
sudo ln -snf /dev/null org.gnome.evolution.dataserver.Sources5.service
sudo ln -snf /dev/null org.gnome.evolution.dataserver.UserPrompter0.service


#############################################################
## Ubuntu - Filesystem
#############################################################

# Show Hide/Hidden Files (Ubuntu)
Control + H

# Mount wired network connection (Ubuntu,linux)
# Useful is policykit-i is accidentally removed
sudo dhclient -v usb0

# Remove trash icon in Ubuntu left panel.
gsettings get org.gnome.shell.extensions.dash-to-dock show-trash   # true
gsettings set org.gnome.shell.extensions.dash-to-dock show-trash false

# Trash folder locaiton on Ubuntu
~/.locat/share/Trash


#############################################################
## Ubuntu - Shortcuts
#############################################################

# Screenshot (Ubuntu)
Druck + Click and drag + Enter    # Snippet.
Shift + Druck                     # Full screenshot.
Control + Alt + Fn + (F1,F2..F12) # Switch display.


#############################################################
## Ubuntu - Filesystem - ZFS
#############################################################

# Create a new zpool
sudo fdisk -l 			# Find device path here

# Destroy (completely remove) a zpool
# WILL DELETE ALL DATA INSIDE
sudo zpool destroy brpool

# Unmount a busy device
umount -l /PATH/OF/BUSY-DEVICE
umount -f /PATH/OF/BUSY-NFS (NETWORK-FILE-SYSTEM)

# ZFS list snapshots
zfs list -r -t snapshot -o name,creation

# Send snapshot backup
sudo zfs send rpool/USERDATA/tim_e5bkz1@autozsys_zh25vd | sudo zfs receive brpool/USERDATA

# Send incremental backup
sudo zfs send rpool@june15b | sudo zfs receive -Fd brpool

# Mount external hard drive with ZFS
sudo zpool list 				# Show available pools
sudo zpool import 			# Shows the brpool name
sudo zpool import brpool	# Import brpool
sudo zpool list 				# Pool now added

# Create a Snapshot with a specific text
sudo zfs snapshot rpool/USERDATA/tim_e5bkz1@june15

# View mounting options for ZFS (zpool)
sudo zfs get 'mountpoint,mounted,canmount' brpool/USERDATA

# zpool status is SUSPENDED
sudo zpool clear brpool
sudo zpool clear -nFX brpool	# Or this

# Cleanup rpool space for zfs
zfs list -t snapshot -o name | while read f; do sudo zfs destroy -r $f; done


#############################################################
## Ubuntu - Flashdrive
#############################################################

# Make bootable flashdrive from iso file (ubuntu)
# Startup Disk Creator
# https://ubuntu.com/tutorials/create-a-usb-stick-on-ubuntu#3-launch-startup-disk-creator

# Automount external hard drive
vi /etc/fstab
UUID=E2B4CF51B4CF273F /media/MY_BACKUP auto nosuid,nodev,nofail,x-gvfs-show 0 2
#
# Find out ID by running
sudo fdisk -l
blkls /dev/<DEVICE>
#
# Or find UUID here for the device
ls -l /dev/disk/by-uuid/

# Backup PC in Ubuntu using timeshift (not for zfs)
https://linuxconfig.org/ubuntu-20-04-system-backup-and-restore

# Allow writing to flash drives
sudo chown $USER:$USER /media/<USER>-srto/ -R


#############################################################
## Ubuntu - Update Error
N#############################################################

# Problem: Did a partial upgrade,
# 	Ubuntu restarted to a black screen and a blinking cursor.
# Fix:
Control + Alt + F2	# At the same time
#
# Login to PC
#
# Finish upgrade
sudo apt update
sudo apt dist-upgrade
sudo startx


#############################################################
## Ubuntu - Drivers
#############################################################

# Reload sound drivers on Ubuntu
sudo alsa force-reload


#############################################################
## Ubuntu - BIOS
#############################################################

# Check BIOS version on the command line (BIOS update).
sudo dmidecode -s bios-version
# Current: N34ET58W (1.58 )
# Old:     N34ET52W (1.52 )

# Find serial number in Ubuntu (BIOS update).
sudo dmidecode -t system | grep Serial  # PF2SHW37

# Update BIOS on Ubuntu Lenovo
# 1. Download iso file from here:
    https://pcsupport.lenovo.com/cz/en/products/laptops-and-netbooks/thinkpad-p-series-laptops/thinkpad-p14s-gen-2-type-20vx--20vy/20vx/20vx0010ge/pf2shw37/downloads/driver-list/component?name=BIOS%2FUEFI&id=5AC6A815-321D-440E-8833-B07A93E0428C
# 2. Flash iso file to harddrive:
    Downloads -> Right Click on iso file
              -> Open with other
              -> Disk image writer.
# 3. Restart PC -> Enter -> F12 -> Select HD.

# Run a system update on Ubuntu
sudo fwupdmgr update     # Updates only the firmware.
#
sudo fwupdmgr install N34ET53W.cab
# (Can get the cat file from:
#   https://pcsupport.lenovo.com/de/de/downloads/ds548904-bios-update-utility-bootable-cd-for-windows-10-64-bit-thinkpad-p14s-gen-2-p15s-gen-2-t14-gen-2-t15-gen-2
#)

# During startup would see:



( run in 1.449 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )