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
1

3 Answers 3

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.
2
  • 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, 2015 at 13:36
  • This is better if you only care about the contents of the files.
    – l0b0
    Mar 18, 2015 at 13:50
3

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

tar cf - <directory name> | sum -

11
  • md5sum not relevant in solaris - tar c folder | md5sum md5sum: Command not found. Mar 18, 2015 at 12:18
  • Does using sum instead of md5sum help? Mar 18, 2015 at 12:20
  • Strange! Can you check sum file.xml once again Mar 18, 2015 at 12:28
  • 1
    no , what its work is that --> tar cf - <directory name> | sum Mar 18, 2015 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, 2015 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
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .