Create a .tar.gz
or .zip
file
tar -czvf file.tar.gz directory-to-compress/
zip -r file.zip directory-to-compress/
Extract contents of a .tar.gz
or .zip
file
tar -zxvf file.tar.gz
unzip file.zip
Create SSH key pair and connect SSH with this key
ssh-keygen -f file_name -C "Comment" # prompts for passphrase
ssh-copy-id -i file_name.pub user@host
ssh -i file_name user@host
Import public key of someone
gpg --import some-one.key
See all imported public keys
gpg --list-keys
Encrypt a file
gpg --encrypt --armor -r [email protected] file.txt # or
gpg -e -u "Sender Name" -r "Receiver Name" file.txt
Decrypt a file
gpg -d file.txt.gpg # to show content directly in bash or
gpg -d file.txt.gpg > file.txt # to create decrypted file
Add existing private SSH key to bash
chmod 600 private.key # set permissions to be only read-writable by me
eval $(ssh-agent -s) # start ssh agent in background
ssh-add private.key # add SSH private key to bash
Count the words of a PDF file:
pdftotext myfile.pdf - | wc -w
Quickly create a random string to use for passwords:
date +%s | sha256sum | base64 | head -c 32 ; echo
curl ipinfo.io/ip
Run database import file on server (corresponding to the phpMyAdmin importer)
mysql -u database_user -p database_name < file.sql
mysql -u database_user -p -h database_host database_name < file.sql # if it's not localhost
Create database export file
mysqldump -u database_user -p database_name > file.sql
Convert all PHP files in the current directory to Unix line endings
find "./" -type f -name '*.php' -execdir dos2unix {} +
Update all outdated packages at once
pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U