I was looking this question and appears everything but crc. Is there a good Ubuntu way around there to do this?
Asked
Active
Viewed 1.3e+01k times
21
-
1CRC means Cyclic Redundancy check. It's a type of (insecure) hash, rather than a specific standard. https://en.wikipedia.org/wiki/Cyclic_redundancy_check lists many kinds of CRC. (CRC32 is perhaps the most common.) – mwfearnley Mar 18 '19 at 12:35
6 Answers
27
$ sudo apt-get install libarchive-zip-perl
$ crc32 my_file

Michael Mrozek
- 123

Alter Lagos
- 1,159
-
4
-
Very helpful for comparing that a file inside a JAR is the correct version. – jjj Oct 06 '17 at 15:40
-
3Adding to what Nemo said, for CentOs, Redhat, Fedora, and similar distros the library is installed with
yum install perl-Archive-Zip
– Terry Sep 25 '19 at 19:33
18
One way to calculate it is this:
cksum "file"
Another one is
crc32 "file"
To use this last command you need to install libarchive-zip-perl
package

Leo
- 3,654
- 2
- 20
- 36
-
8
-
I don't know which type of CRC the OP had, but the version of
cksum
on my Linux box (a Synology NAS unit) can produce four different outputs. One with no parameters (cksum file
) but it also accepts-o1
through-o3
options. Using-o3
produces the same value as used in "CSV verification files" (albeit it produces them in decimal, the files have them in hex)... that might be the same algorithm as the OP needs. – TripeHound Nov 20 '20 at 12:29 -
@TripeHound The cksum version (9.1) currently in debian 12 doesn't seem to have any -o1 through -o3 algorithms. But it does have the -a / --algorithm options, however none appear to match the crc32 from libarchive-zip-perl, cksfv, or rhash. Even cksum's
crc
algorithm outputs a decimal number that does not convert to the same hex the others report – Xen2050 Feb 19 '24 at 00:58
4
I'd use the internal md5sum
one of the provided sha programs:
sha1sum (1) - compute and check SHA1 message digest
sha224sum (1) - compute and check SHA224 message digest
sha256sum (1) - compute and check SHA256 message digest
sha384sum (1) - compute and check SHA384 message digest
sha512sum (1) - compute and check SHA512 message digest
cksum
is pretty much outmoded these days because of its problems.

mdpc
- 1,199
-
3What problems? I want to know if two files are duplicates - is
cksum
not good enough for that purpose? – Marc.2377 Nov 24 '19 at 06:06 -
Perhaps the "problem" is the fact that CRC is not a cryptographic hash (meaning it's considered easy to create two files with different contents that have the same CRC if that's what you're trying to do). However, when you're talking about random errors, CRC is not too bad AFAIK. – adentinger Jan 28 '20 at 19:28
-
2CRC is about 10x faster than md5 in my current tests. So CRC vs md5/sha involves a tradeoff between key space (probability of accidental collision) and performance. In a small device or with high data volume performance might matter. – Joseph Sheedy Feb 11 '21 at 17:11
4
-
2
-
cksfv -c "file"
prints the CRC32 to stdout. If you want to suppress the header, acksfv -c "file" 2>/dev/null | grep -v ^\;
gives the filename + CRC32 and no warning for a directory. – emk2203 Jun 14 '19 at 17:12
3
You can try to use rhash
.
- http://rhash.sourceforge.net/
- https://github.com/rhash/RHash
- http://manpages.ubuntu.com/manpages/bionic/man1/rhash.1.html
Test:
$ sudo apt-get install rhash
$ echo -n 123456789 | rhash --simple -
cbf43926 (stdin)

Woosung
- 31
0
you can accomplish this with a very simple perl script. use String::CRC32;
my $s = <STDIN>;
my $crc = crc32($s);
printf "%08x\n", $crc;
-
Sounds good, but how can someone with zero perl knowledge turn this into a working answer? Or even a one liner? – Xen2050 Feb 19 '24 at 00:14