Common #
Generate password #
$ openssl rand -base64 14
$ gpg --gen-random --armor 1 14
$ cat /dev/urandom | tr -dc a-zA-Z0-9 | fold -w 14 | head -n 1
Generate missed pub key from private #
$ ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
Create a large file #
- Linux & all filesystems
xfs_mkfile 10240m 10Gigfile
- Linux & and some filesystems (ext4, xfs, btrfs and ocfs2)
fallocate -l 10G 10Gigfile
- OS X, Solaris, SunOS and probably other UNIXes
mkfile 10240m 10Gigfile
Date and time transformations #
# GNU date
timestamp -> human-readable
date -d @1339471282
human-readable -> timestamp
date --date="Tue 21 Jul 2020 03:56:50 PM MS" +"%s"
# BSD date
timestamp -> human-readable
date -r 1282368345
human-readable -> timestamp
date -j -f "%Y-%m-%d %H:%M:%S" "2018-01-30 15:58:50" "+%s"
MySQL #
Change user pass #
ALTER USER 'user'@'localhost' IDENTIFIED BY 'NEW_USER_PASSWORD';
FLUSH PRIVILEGES;
Granting User Connections From Remote Hosts: #
GRANT ALL PRIVILEGES ON *.* TO 'user'@'host' IDENTIFIED BY 'my-new-password' WITH GRANT OPTION;
PostgreSQL #
Create new user and DB #
sudo -u postgres createuser new-user
sudo -u postgres createdb new-db
sudo -u postgres psql
alter user new-user with encrypted password 'secret-pass';
grant all privileges on database new-db to new-user;
Git #
Empty commit #
git commit --allow-empty -m "Empty commit message"
Rename local branch #
git checkout ${TARGET_BRANCH}
git branch -m ${NEW_BEANCH_NAME}
Copy file from other branch #
git checkout ${SOURCE_BRANCH} /path/to/file
Tmux #
:setw synchronize-panes
Windows cmd #
reg - regestery managging tool
reg query HKEY_LOCAL_MACHINE # shows all keys in selected branch
wevtutil - shows Windiows logs
wevtutil el # shows all available logs
wevtutil qe ${LOG_NAME} # shows events from selected log
systeminfo - provides software and hardware information
WSL #
wsl -l -all # List of all available distros
wsl -s ${distro_name} # Set a distro as default
wsl --unregister ${distro_name} # Delete distro
K8S #
Merge multiple kubectl configs into a single file #
# Make a copy of your existing config
$ cp ~/.kube/config ~/.kube/config.bak
# Merge the two config files together into a new config file
$ KUBECONFIG=~/.kube/config:/path/to/new/config kubectl config view --flatten > /tmp/config
# Replace your old config with the new merged config
$ mv /tmp/config ~/.kube/config
# (optional) Delete the backup once you confirm everything worked ok
$ rm ~/.kube/config.bak