3

On my Solaris machine, I sometimes use the sum command to verify that a file has not changed. I now want to check whether a directory's contents have changed but sum only runs on files.

Is there a way to run sum or a similar command on an entire directory?

Example sum on a file:

$ sum  file.xml
27247 11 file.xml
3

Use tar to create tarball of directory and run sum on it then.

tar cf - <directory name> | sum -

  • md5sum not relevant in solaris - tar c folder | md5sum md5sum: Command not found. – maihabunash Mar 18 '15 at 12:18
  • Does using sum instead of md5sum help? – Milind Dumbare Mar 18 '15 at 12:20
  • Strange! Can you check sum file.xml once again – Milind Dumbare Mar 18 '15 at 12:28
  • 1
    no , what its work is that --> tar cf - <directory name> | sum – maihabunash Mar 18 '15 at 13:20
  • 3
    tar will also include ownership, permissions and timestamps, so unless you care about those (normally you wouldn't) this is a bad idea. – l0b0 Mar 18 '15 at 13:50
6

1) do a reference:

find . -type f -exec sum {} \; | sort -k3 > /my/reference.txt

2) do a run time check

find . -type f -exec sum {} \; | sort -k3 | diff /my/reference.txt -

where

  • sort -k3 do a sorting on file name
  • diff part will show file changed, added or deleted.
  • I very much prefer this solution of the other answers as it might not always be feasible to create a tarball of the directory/directories in questions, e.g. when disk space is a limiting factor. Although the diff gives you richer information of the changes, if you want to have a single sum as a result/reference, you can obviously pipe on the results of the sort commands to sum instead of saving them to a file. – inVader Mar 18 '15 at 13:36
  • This is better if you only care about the contents of the files. – l0b0 Mar 18 '15 at 13:50
2

On Solaris tar works differently. So either use gtar from GNU or use tar cf - and then the solution from Miline:

tar cf - folder | sum

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.