Create a Makefile
with the following contents:
SHAS := $(patsubst folder/%, sha/%, $(shell find folder/ -type f))
all: sha $(SHAS) checksumfolder.txt
sha:
mkdir sha
sha/%: folder/%
sha256sum $< > $@
checksumfolder.txt: $(SHAS)
cat $(SHAS) > checksumfolder.txt
When you now run make
inside the parent directory of folder/
, a new sha/
directory will be created containing the sha256sum of each file in folder/
. At the end we concatenate all files into checksumfolder.txt
.
When you run make
a second time, nothing will be done.
When you touch a file in folder/
or create a new one and run make
the sha256sum of this specific file gets updated.
To learn more about make
run info make
.
If you never change a file (only add new ones), you could simply remember the file name with the most recent modification time when you last ran the find
command and select only the newer files with:
find -newer REFERENCE_FILE
… or a direct timestamp (see date(1) DATE STRING) with
find -newermt TIME_STAMP