General Linux

Copy Progress

With cp and pv

cp -r /the/source /the/destination | pv -lep -s $(du -sb /the/source | awk '{print $1}') >/dev/null

With rsync

rsync -aP /the/source /the/destination

With cp and bar

cp -r /the/source /the/destination | bar

Kill All Processes Owned by a User

sudo kill -9 $(pgrep -u username)

Show SSL Certificate (HTTPS or Not)

# HTTPS website
openssl s_client -showcerts -servername docs.rda.run -connect docs.rda.run:443 < /dev/null

# Any other TLS service still works
openssl s_client -showcerts -servername tlshost.example.org -connect tlshost.example.org:49056 < /dev/null

Show Dell Service Tag

sudo dmidecode -s system-serial-number

Using a Lockfile to Run a Script Only One at a Time

#!/bin/bash

lockfile="$0.lockfile"

if [[ -e "$lockfile" ]] && ! kill -0 "$(< "$lockfile")" 2>/dev/null; then
	echo "Warning: lockfile exists but the process is dead, continuing."
	rm -f "$lockfile"
elif [[ -e "$lockfile" ]]; then
	echo "My important work is already running. Exiting."
	exit 1
fi

printf '%s\n' "$$" > "$lockfile"

# Add all your important stuff here.

rm -f "$lockfile"

exit 0

Viewing Crontab of All Users

for user in $(cut -f1 -d: /etc/passwd); do echo $user; sudo crontab -u $user -l; done

Simulating the Java trim() in Bash

echo " test test test " | sed -e 's/^ *//' -e 's/ *$//'

Reference: StackOverflow