Shell Hacks¶
Network¶
Generate a DUID
echo 0004$(uuidgen | tr -d -)
Time¶
Continuously display time¶
while true; do echo -ne "date\r"; done
Continuously display time with nanoseconds¶
while true; do echo -ne "date +%H:%M:%S:%N\r"; done
Stopwatch¶
date1=date +%s; while true; do
echo -ne "$(date -u --date @$((date +%s- $date1)) +%H:%M:%S)\r";
done
Countdown¶
seconds=20; date1=$((date +%s+ $seconds));
while [ "$date1" -gedate +%s]; do
echo -ne "$(date -u --date @$(($date1 -date +%s)) +%H:%M:%S)\r";
done
ffmpeg aac to mp3¶
for i in *.m4a; do
ffmpeg -i "$i" -acodec mp3 -ac 2 -ab 160 "$i".mp3
done
Removing Metadata from an Image¶
exiv2 rm *.JPG
Scaling Image Dimensions of an Image File¶
mogrify -resize 80% *.JPG
Passing an Associative Array to a Function¶
function eins {
eval "declare -A array2="${1#*=}
echo "${array2[name]}"
echo "${array2[key]}" }
declare -A array1
array1[name]="test"
array1[key]="value"
echo ${array1[name]}
echo ${array1[key]}
eins "$(declare -p array1)"
Appending a String¶
for i inls; do
sed -i -e 's/^/string_to_prepend/' $i
done
Generate QR Code from PGP Key¶
-
Install the qrencode package
gpg --fingerprint <
> echo "your fingerprint with whitespaces" | awk '{ gsub(/ /,""); print }' -
Convert the new key without spaces into a URI:
OPENPGP4FPR:1357B01865B25D3C18453D208CAC1A9678448E35 qrencode -t PNG 'OPENPGP4FPR:1357B01865B2503C18453D208CAC2A9678548E35'> pgp_qr.png
This is what my QR code looks like for jochen@libcom.de:
jochen@libcom.de