LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices


Reply
  Search this Thread
Old 05-26-2017, 10:39 AM   #1
robertkwild
Member
 
Registered: Feb 2015
Posts: 334

Rep: Reputation: Disabled
how to checksum on file/folder


hi all,

how do you do a checksum of a file folder, i want to use sha512 as md5 is cracked

file -


sha512 path/to/file/file.tar


folder -


find -s path/to/folder -type f -exec sha512 {} \; | sha512


many thanks,

rob

Last edited by robertkwild; 05-26-2017 at 10:42 AM.
 
Old 05-26-2017, 11:00 AM   #2
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,640
Blog Entries: 3

Rep: Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160
First, someone has to have made a list of files and their checksums. You can do that, if the files are yours and you know they are good.

Code:
sha512sum /path/to/some/directory/*.tar > checksums.sha512; done
Then once you have a file with the checksums with two columns, the first being the checksum, the second being the file name, someone else receiving the files in question plus the checksum file can verify it.

Code:
sha512sum -c checksums.sha512
The checksums are intended to guarantee integrity. Often for further guarantees of authenticity, the checksums are usually signed with OpenPGP. The utility gnupg, version 1.x can do that.

Last edited by Turbocapitalist; 05-26-2017 at 11:05 AM. Reason: simplified
 
Old 05-26-2017, 11:08 AM   #3
robertkwild
Member
 
Registered: Feb 2015
Posts: 334

Original Poster
Rep: Reputation: Disabled
what does the option -c do

also i imagine your first code i will put it in a script?
 
Old 05-26-2017, 11:11 AM   #4
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,640
Blog Entries: 3

Rep: Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160
From the manual page for sha512sum it says:

Quote:
-c, --check
read SHA512 sums from the FILEs and check them
The first draft, before the edit, was more script-oriented.
 
Old 05-26-2017, 11:13 AM   #5
robertkwild
Member
 
Registered: Feb 2015
Posts: 334

Original Poster
Rep: Reputation: Disabled
so cant i do just

sha512 filename.tar

or should it be

sha512 -c filename.tar

i thought your first code was to be put in a script, i will do that and get back to you

thanks man
 
Old 05-26-2017, 11:17 AM   #6
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,640
Blog Entries: 3

Rep: Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160
This will generate a checksum and save it in a file:

Code:
sha512 filename.tar > filename.sha512
The following will use that checksum file to verify the other file(s)

Code:
sha512 -c filename.sha512
It's kind of pointless to do both yourself. Usually that second step is done by someone else to verify that a transfer was successful.

Last edited by Turbocapitalist; 05-26-2017 at 11:19 AM.
 
Old 05-26-2017, 11:38 AM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,792

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
It looks like you missed a very important point: check in this case means you check your file against an external information, which is called checksum (and actually is another file)
Usually you download a file and a checksum too and you can check if the checksum of the given file is identical to the checksum downloaded. (if yes we assume the downloaded file is ok, if not we assume the download was unsuccessful.
Code:
sha512 filename.tar > filename.sha512
creates the checksum
Code:
sha512 -c filename.sha512
checks if that checksum is valid
 
Old 05-26-2017, 11:56 AM   #8
robertkwild
Member
 
Registered: Feb 2015
Posts: 334

Original Poster
Rep: Reputation: Disabled
ok i have done a file by doing this -

sha512 Even\ When\ I\ Fall\ -\ January\ 2017\ Project.tar

how do i do a directory now

many thanks,

rob
 
Old 05-26-2017, 12:02 PM   #9
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,792

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
Quote:
Originally Posted by robertkwild View Post
ok i have done a file by doing this -

sha512 Even\ When\ I\ Fall\ -\ January\ 2017\ Project.tar
what do you mean by that?
Quote:
Originally Posted by robertkwild View Post
how do i do a directory now
And again, what do you want to do? I'm afraid, there is no such thing for directories, but files.
 
Old 05-26-2017, 12:06 PM   #10
robertkwild
Member
 
Registered: Feb 2015
Posts: 334

Original Poster
Rep: Reputation: Disabled
sorry i mean this -

sha512 Even\ When\ I\ Fall\ -\ January\ 2017\ Project.tar
SHA512 (Even When I Fall - January 2017 Project.tar) = fa8a0c210f4616f27de9e66d5316bce62881baf794214ebecbf4a6fd576e09b274b278f0bef278315e12159083073975f02e 5f03aff18682e5273722287df799

ok so now i know what the checksum is for the tar file

now i want to find out what the checksum is for the directory (i created the directory into the tar file)

i want to check if the two have the same checksums

Last edited by robertkwild; 05-26-2017 at 12:08 PM.
 
Old 05-26-2017, 12:53 PM   #11
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,640
Blog Entries: 3

Rep: Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160
There can be no checksum for the directory itself, it is not a file, only for any files that might be in the directory.

Code:
sha512 *.tar > directory.sha512
 
Old 05-26-2017, 01:03 PM   #12
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,792

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
only files can have checksums, and if that dir could have a checksum that would be definitely different (so not the same as the one you posted)
 
Old 05-26-2017, 04:22 PM   #13
cynwulf
Senior Member
 
Registered: Apr 2005
Location: Walsall, England
Posts: 1,973
Blog Entries: 5

Rep: Reputation: 1012Reputation: 1012Reputation: 1012Reputation: 1012Reputation: 1012Reputation: 1012Reputation: 1012Reputation: 1012
What you clearly want to do is crc check a tar file. gzip does this, so if you gzip the tar using the z command line option it will add the checksum.

Refer to tar(1), gzip(1)

And this:
Quote:
Originally Posted by pan64 View Post
only files can have checksums, and if that dir could have a checksum that would be definitely different (so not the same as the one you posted)
 
Old 05-26-2017, 05:27 PM   #14
robertkwild
Member
 
Registered: Feb 2015
Posts: 334

Original Poster
Rep: Reputation: Disabled
wow, wasnt expecting this, im getting all different checksum values

i think i will extract the tar and cross reference it with the source directory ie do on both

count number of files

size of directory

SHA512 (/vol/cha-work/_ARCHIVE/to_be_archived/audio/chad_r/2017-05-17/Even When I Fall - January 2017 Project.tar) = fa8a0c210f4616f27de9e66d5316bce62881baf794214ebecbf4a6fd576e09b274b278f0bef278315e12159083073975f02e 5f03aff18682e5273722287df799

find -s /vol/cha-work/_ARCHIVE/to_be_archived/audio/chad_r/2017-05-17/Even\ When\ I\ Fall\ -\ January\ 2017\ Project/ -type f -exec sha512 {} \; | sha512
9bc5b7f9b2dcf68fc5b113cd359282e34876ad796c43e5b16701c9ff0cba3ba3b038af67db9f8a8dbadfa6d22ee3584f1c4a c840b710c5f422d7435f59c09c42

tar -cf - Even\ When\ I\ Fall\ -\ January\ 2017\ Project/ | sha512
ac81d3bc9dc843fd4c7d6e6bdbc477076437727044f291b5c162232efb8e8747c8b2d2bd82567e381ea235d158fba5d28e3c 5eab9a60a86acba6b452960bb7da

Last edited by robertkwild; 05-26-2017 at 05:58 PM.
 
Old 05-26-2017, 09:14 PM   #15
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Ubuntu, Devuan, OpenBSD
Posts: 2,640
Blog Entries: 3

Rep: Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160Reputation: 1160
Quote:
Originally Posted by robertkwild View Post
find -s /vol/cha-work/_ARCHIVE/to_be_archived/audio/chad_r/2017-05-17/Even\ When\ I\ Fall\ -\ January\ 2017\ Project/ -type f -exec sha512 {} \; | sha512
9bc5b7f9b2dcf68fc5b113cd359282e34876ad796c43e5b16701c9ff0cba3ba3b038af67db9f8a8dbadfa6d22ee3584f1c4a c840b710c5f422d7435f59c09c42

tar -cf - Even\ When\ I\ Fall\ -\ January\ 2017\ Project/ | sha512
ac81d3bc9dc843fd4c7d6e6bdbc477076437727044f291b5c162232efb8e8747c8b2d2bd82567e381ea235d158fba5d28e3c 5eab9a60a86acba6b452960bb7da
You're sending different data to sha512. In the first line, you send only the file itself to sha512 and then make an SHA512 hash of that hash. In the second line, you are providing a complete tarball to it.

Last edited by Turbocapitalist; 05-26-2017 at 09:17 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
recursive file and checksum comparison dsh Linux - General 4 10-28-2009 12:29 AM
Checksum 4 Slackware download - what type of checksum is this. Earnest Lux Linux - Newbie 1 02-02-2008 09:02 PM
SUID file checksum change paul123 Linux - Security 3 01-15-2007 05:57 PM
checksum a file? Moses420ca Linux - Security 2 08-17-2003 02:27 PM

LinuxQuestions.org > Forums > Other *NIX Forums > *BSD

All times are GMT -5. The time now is 11:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration