The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cksum dependencies vibhor_agarwali UNIX for Advanced & Expert Users 3 09-05-2007 02:38 AM
using cksum leeRoberts2007 Shell Programming and Scripting 4 05-31-2007 09:30 PM
The cksum Problem Dim-Wit Shell Programming and Scripting 7 08-15-2006 02:03 PM
cksum question rjsha1 Shell Programming and Scripting 4 01-17-2006 11:44 AM
cksum parts of a file crazykelso UNIX for Dummies Questions & Answers 6 07-30-2002 11:38 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-27-2004
kapolani kapolani is offline
Registered User
  
 

Join Date: Oct 2004
Posts: 11
Anyone know how cksum works?

hello all.

I'm not asking about the algorithm - or how it goes about computing the checksum - I'm asking how it views/looks at the files it does the cksum on.

For instance:

Say you had a directory named "dir_A"

And within this directory you had some files.

So:

dir_A
- file1
- file2
- file3

Do you have to step through dir_A and compute a cksum for EACH individual file?

For instance:

% cd dir_A
% cksum file1
% return some number
% cksum file2
% return some number
% cksum file3
% return some number

Or, can I just compute the cksum for the whole directory?

For instance:

% cksum dir_A
% return some number

If one of the files within dir_A changes and I redo the cksum is it safe to say that a valid cksum will be computed for the whole directory? What if file1 WITHIN dir_A changed - will the cksum change?

Or, do you have to compute a cksum for each individual file?

Thanks!!!
  #2 (permalink)  
Old 10-27-2004
RTM's Avatar
RTM RTM is offline Forum Advisor  
Hog Hunter
  
 

Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
Why didn't you try it to see???

You can't run checksum on a directory (or I couldn't).

To do a checksum on the files in the directory,

$ sum ./directory/*.*
Note that it won't do hidden files.
  #3 (permalink)  
Old 10-27-2004
locustfurnace locustfurnace is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2004
Posts: 232
You can cksum or md5 a directory. I am able to accomplish this on FreeBSD, but under Slackware, it does not appear to work.
If you want you can redirect the md5 into a txt file, so you can check it later.
Changing a file in the directory won't change the cksum, md5. (correction), but adding or removing files will.

you can issue
cksum A_dir
md5 A_dir

Last edited by locustfurnace; 10-28-2004 at 11:28 AM..
  #4 (permalink)  
Old 10-28-2004
kapolani kapolani is offline
Registered User
  
 

Join Date: Oct 2004
Posts: 11
Quote:
Originally posted by RTM
Why didn't you try it to see???

You can't run checksum on a directory (or I couldn't).

To do a checksum on the files in the directory,

$ sum ./directory/*.*
Note that it won't do hidden files.
LOL..

I did try it. It worked for me.

I'm running digital unix tru64 4.0f.

%cksum dir_A
% 12345678 8908 dir_A

I changed a file in dir_A and got another number.

I was just curious if the number computed can be reliable or am I missing something...

Thanks for the replies...
  #5 (permalink)  
Old 10-28-2004
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
Registered Geek
  
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
I believe that the cksum is being computed on the directory entry itself - i.e. the actual "file" on disk that contains a list of the files that the directory contains.

e.g. under HP-UX 10.20
If you do
$ sum dir_A
2022 2 dir_A
This is the same as
$ cat dir_A | sum
2022 2

Then,
Code:
$ sum dir_A
2022 2 dir_A
$ touch dir_A/foo
$ sum dir_A
2492 2 dir_A
$ vi dir_A/foo		# add two hundred lines of whatever
$ sum dir_A
2492 2 dir_A		# see - file has changed, but checksum hasn't
$ rm dir_A/foo
$ sum dir_A		
2022 2 dir_A		# now checksum has returned to previous value
So, from what I can see, only the addition and removal of files within the directory (thus changing the directory entry) will actually modify the checksum. If you change the contents of a file, this won't make a difference.

It looks you would have to do something like (as previously mentioned)
$ sum dir/* >list # or cksum dir/*, md5sum dir/*, whatever
To get a list of checksums and then periodically verify those.

Same results seem to appear with cksum.

I don't know if this helps/answers any questions, but it's a result of my probing around.

Oh, some versions of Linux/UNIX don't allow you to compute checksums on directories, also mentioned above....
  #6 (permalink)  
Old 10-28-2004
kapolani kapolani is offline
Registered User
  
 

Join Date: Oct 2004
Posts: 11
Quote:
Originally posted by zazzybob
I believe that the cksum is being computed on the directory entry itself - i.e. the actual "file" on disk that contains a list of the files that the directory contains.
I don't know if this helps/answers any questions, but it's a result of my probing around.

Oh, some versions of Linux/UNIX don't allow you to compute checksums on directories, also mentioned above....
That's what I was curious about.

I got mixed results when I tested it myself, but was unable to figure out what was going on.

That's very helpful.

Thanks.
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:35 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0