Some useful Bash commands

This blog post includes a few useful Bash commands. Other blog posts will follow.

Delete recursive all files with the same extension. To verify if the right files are found, use the command without the option -delete:

find . -name "*.bak" -type f -delete

Print the fingerprint of a public key without importing the key:

gpg2 --with-fingerprint <public-key.asc>

Upgrade python packages for python3 via pip

pip3 freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip3 install -U

New versions of ssh show the fingerprint as sha256. If you have an older version installed on your server, it's printed as MD5 hash. To make it easier to compare the fingerprints, specify the following option if you connect via ssh from the client:

ssh -o FingerprintHash=md5

The following command can be used to create an encrypted archive with 7z from the command line. The filenames inside the archive are encrypted as well.

7z a -p -mhe=on <archive-name.7z> <files or directory to add> 

a    ... add files to archive
-p   ... ask for a password to protect the archive
-mhe ... enables or disables archive header encryption