I always write little scripts and aliases that help me from time to time. I just wanted to share some of my newest simple scripts. There are probably better or easier ways to do, but writing and testing them is fun too. Both make use of the 7z
command, a commandline archive tool. Posting it here, so anyone can steal them. They are freshly written, so maybe there are edge cases.
#!/usr/bin/env bash
# Calculate CRC32 for each file.
if [ "${#}" -eq 0 ]; then
echo "crc32sum files..."
echo "crc32sum *.smc"
else
7z h -- "${@}" |
\grep --after-context "${#}" '^-------- ------------- ------------$' |
\grep --before-context "${#}" '^-------- ------------- ------------$' |
awk '{print $1 "\t" $3}' |
\grep -P '^[0-9A-Z]+\t'
fi
#!/usr/bin/env bash
# Create one archive for each file or folder.
if [ "${#}" -eq -1 ]; then
echo "toarchive ext files..."
echo "toarchive zip *.smc"
else
ext="${1}"
shift
opt=()
stop_parse=false
for arg in "${@}"; do
if [ ! "${stop_parse}" == true ]; then
if [ "${arg}" == "--" ]; then
stop_parse=true
opt+=(--)
continue
elif [[ "${arg}" =~ ^- ]]; then
opt+=("${arg}")
continue
fi
fi
file="${arg}"
7z a "${opt[@]}" "${file}.${ext}" "${file}"
done
fi
Zstd gang
I use Zstd specifically with
tar
to make backups ever since I realized how fast it is. But that is a complete different thing than this day to day tool, where Zstd is not needed.