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
maihabunash
  • 7,131

3 Answers3

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.
Archemar
  • 31,554
  • 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
3

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

tar cf - <directory name> | sum -

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
Ondrej
  • 156