Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 24th July 2006, 05:52 PM
suranjith Offline
Registered User
 
Join Date: Jul 2006
Posts: 15
MD5 for folder

Hi all,
I am trying to calculate the MD5 sum for a folder using md5sum.
Can't find any documentation on this.
Would be grateful for any pointers .
Best regards,
Suranjith
Reply With Quote
  #2  
Old 24th July 2006, 08:09 PM
daneel971's Avatar
daneel971 Offline
Registered User
 
Join Date: Jun 2005
Location: Italy
Posts: 1,108
I'm not sure md5sum works on directories, but cfv does - and has a good manpage. It's in the extras repo.
__________________
- Captain...
- Yes, Spock?
- I can't believe my ears...
Reply With Quote
  #3  
Old 24th July 2006, 09:54 PM
suranjith Offline
Registered User
 
Join Date: Jul 2006
Posts: 15
Thanks daneel.
Suranjith
Reply With Quote
  #4  
Old 2nd January 2009, 01:46 AM
suranjith Offline
Registered User
 
Join Date: Jul 2006
Posts: 15
Yet again I need to solve the same problem, namely can you MD5 a folder ?
Any developments since I posted this question about 2.5 years ago ?
Thanks
Reply With Quote
  #5  
Old 2nd January 2009, 04:54 PM
aleph's Avatar
aleph Offline
Banned (for/from) behaving just like everybody else!
 
Join Date: Jul 2007
Location: Beijing, China
Posts: 1,307
It doesn't work in that way.

MD5 hashing works on byte sequences. When you take the MD5 checksum of a file, you are using the file's whole range as the input sequence. However, it doesn't make sense for a directory because it is not represented in the same way as a non-directory file. What defines a (regular) "file" is a set of operations that can be done to it, and not all of these operations can be applied to a directory.

To generate the hashes of all files in a directory, simply take the sum of it's files recursively.
Code:
$ find foo/ -type f -exec md5sum {} \; > SUMS
where foo is the directory to be checked and SUMS is the output file containing a table of hash value -- file path pairs. Be sure don't put the file SUMS under foo itself, otherwise funny things will happen.

The ">" operator in the above code truncates the file SUMS if it's already there. If this is not desired, change it to ">>", which allows the output to be appended to the file.

To check the files' integrity, just use
Code:
$ md5sum -c SUMS
and the program will take care of the rest.

There's a caveat though. The paths saved in the SUMS file are affected by the path argument passed to "find". If you did "find foo/ ..." they would look like "foo/bar/baz ..." but if you did "find ./foo/" they'd be "./foo/bar/baz ...". Be sure you don't confuse md5sum when you are checking the files. One of the situations may be like this: you recorded in the SUMS the *absolute* paths of each file, and later you copied the directory tree to another place so the absolute paths changed. After that, md5sum will complain that it can't find the files to check.

Alternatively you can just archive the whole directory to a .tar file and take the checksum of that. However by doing so you lose the information of each individual file's checksum.
__________________
I believe in nerditarianism. I read FedoraForum for the Fedora-related posts.

Last edited by aleph; 2nd January 2009 at 05:03 PM.
Reply With Quote
  #6  
Old 2nd January 2009, 06:15 PM
sideways's Avatar
sideways Offline
Retired User
 
Join Date: Oct 2004
Location: London, UK
Posts: 4,999
another option is to use tar and pipe to md5sum

Code:
tar c <directory> | md5sum
but to be reliable the same version of tar would need to be used in generating and checking the md5sum
Reply With Quote
Reply

Tags
find, md5sum

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mounting a folder in a partition to anoter folder Galvin Tjime Using Fedora 1 13th June 2009 09:31 AM
file/folder Properties: date created missing & access means expose in open folder Nick Levinson Using Fedora 4 17th February 2009 12:07 AM
Home folder vs. root Home folder? bisctboy Installation and Live Media 6 20th March 2006 03:28 AM
mounting a NTFS folder on my /home/myuser folder jaguero Using Fedora 3 26th October 2005 10:54 PM


Current GMT-time: 04:32 (Wednesday, 22-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat