LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How do you cksum a directory? (https://www.linuxquestions.org/questions/linux-general-1/how-do-you-cksum-a-directory-803863/)

custangro 04-23-2010 06:28 PM

How do you cksum a directory?
 
How can I checksum a directory?

Using both cksum and md5sum yields the same error

Code:

root@linux# cksum /bin
cksum: /bin: Is a directory
root@linux# md5sum /bin
md5sum: /bin: Is a directory

In Solaris 10 it works

Code:

root@solaris# cksum /bin
356121957      19968  /bin

How can I get the same fuctionality on Linux?

-C

AlucardZero 04-23-2010 06:49 PM

You can't. And on Solaris you're getting the cksum of the directory entry itself, not any of the file in it.

custangro 04-24-2010 11:44 AM

Quote:

Originally Posted by AlucardZero (Post 3945833)
And on Solaris you're getting the cksum of the directory entry itself, not any of the file in it.

Which is what I want :)

Quote:

Originally Posted by AlucardZero (Post 3945833)
You can't.

That's a shame :(

-C

custangro 05-04-2010 10:32 AM

Quote:

Originally Posted by custangro (Post 3946409)
Which is what I want :)



That's a shame :(

-C

Okay I "solved this" by creating a function...

Code:

check_sum () {
  dir=$1 
  dirsum=0
  for sum  in $(find ${dir} -type f | xargs cksum | awk '{print $1}')
  do
    dirsum=$(( ${sum} + ${dirsum} ))
  done
  print ${dirsum}
}

And calling it in my script like so...

Code:

check_sum /bin
-C


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