我必须编写一个命令,我们必须找到文件,计算一个md5代码,然后将其放入文本文件中。找到这些文件并不难,只是将stdin作为参数传递给sed
find -type f
现在我有一个文件列表,并为每个文件我必须要找到MD5码。我知道代码生成MD5码
openssl dgst -md5 <file>
但我怎么使用管道(无脚本)有类似this`
filename md5code
我已经尝试过
while read line do... done
但那没用。我认为我必须使用sed,但我现在不是真的如何。我最近尝试(我认为)是这样的:
find dir -type f | sed "s/^\(.*\)$/\1 $(openssl dgst -md5 \1)/" >> file.txt
但它不承认\ 1 ...
我在找到这样的-exec选项试了一下:
md5$ find dir -type f -exec sed "s/^\(.*\)$/\1 $(openssl dgst -md5 {})/" \;
但它不承认{}
谢谢!这工作,没有想到-printf。 – micro