Skip to content

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 -connect < /dev/null

# any other tls service still works
openssl s_client -showcerts -servername -connect < /dev/null

show dell service tag

sudo dmidecode -s system-serial-number

using a lockfile to run a script only one at a time



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

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