I could manage to generate a hash file for each file not yet hashed recursively:
find . -type f ! -name '*.sha256' -execdir sh -c '[ ! -f "$1.sha256" ] && sha256sum "$1" > "$1.sha256"' _ {} ;
I can´t get it to produce hidden files prefixed with a dot. Adding a . like so
find . -type f ! -name '*.sha256' -execdir sh -c '[ ! -f "$1.sha256" ] && sha256sum "$1" > ".$1.sha256"' _ {} ;
Produces no output.
I can´t figure out how to add the . prefix or how to escape it.
I tried to isolate the variable like ${1} or {$1} also didn´t help.
I got the current generation for non hidden files extrapolated from this question and its solution
Create separate MD5 file for each file recursively
I would be perfectly happy to have bash script to call to do the job if it is easier to produce.
I would need the solution to work on debian and ubuntu linux.
2
Answers
As I was unable to handle it in a shell call I resorted to a python script. I could not wrap my head around how to make use of suggested basename neither had success with using exec instead of execdir.
I'd still be interested out of curiosity if some one could provide me a working line of shell code.
Until that I will work with the following python code
At least I'm still able to use find to verify my hashes ;)
Firstly, you check for
"$1.sha256"
but then try to create".$1.sha256"
.Secondly and more importantly, when a command is invoked from
execdir
, its argument will always start with./
. Prepending a dot to it won’t do you much good. You can usebasename
to get rid of the./
.