I would like to generate sha256 hash for each log file in a folder and store that hash in a file named by the original file name suffixed with ".sha265" int he same folder.
For example, I would like to store the hash for /path/file.ext
into /path/file.ext.sha256
I succeed in generating the hashes but fail in creating the .sha256 files. Here is how are generated the hashes :
find /data/dump/ -type f -name "*.log" -exec sha256sum {} \;
Any help would be appreciated ! :)
This should work:
The
sh -c
part is called inline-script. See this for reference.If you want to save only the sha256, you can pipe the sha256 utility with awk:
The backslash before
$1
is required to avoid unwanted parameter expansion.Try with the following test command
and if it works, remove the
echo
:The single and double quotes are there to make it work. It is extra complicated if there are special characters in the file names, for example spaces.
It works for me in a test directory. If it does not work for you, you can 'see' what happens and modify the expression using the output when
echo
is there.