Last active
April 18, 2025 15:22
-
-
Save thingsiplay/5f07e82ec4138581c6802907c74d4759 to your computer and use it in GitHub Desktop.
crc32sum - Calculate CRC32 for each file (Bash using 7z)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [[ "${#}" -eq 0 ]] || [[ "${1}" == '-h' ]]; then | |
self="${0##*/}" | |
cat <<EOF | |
usage: ${self} files... | |
Calculate CRC32 for each file. | |
positional arguments: | |
file or dir one or multiple file names or paths, if this is a directory | |
then traverse it recursively to find all files | |
EOF | |
exit 0 | |
fi | |
7z h -bsp2 -- "${@}" | | |
\grep -v -E '^[ \t]+.*/' | | |
\sed -n -e '/^-------- ------------- ------------$/,$p' | | |
\sed '1d' | | |
\grep --before-context "9999999" '^-------- ------------- ------------$' | | |
\head -n -1 | | |
\awk '$2=""; {print $0}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The initial version of this script was actually broken. It would not output all files if a directory was included (wrong counting of files through argument number). Also filenames that contained a space would only output the first part until the space character.
All of this rookie mistakes are solved. Plus there is a progress bar showing what files are processed at the moment, instead showing a blank screen until command is finished. This is useful if there are a lot of files or some big files to process.