简体   繁体   English

在Linux中打印md5sum的find命令结果

[英]Print md5sum of results of a find command in Linux

I am tryng to do checksum on all .jar files I can find in directory and its sub directories. 我正在尝试对我可以在目录及其子目录中找到的所有.jar文件执行校验和。 Then print the filename with the checksum value to a file. 然后将带有校验和值的文件名打印到文件中。

this is what I have. 这就是我所拥有的。

md5sum | find -name *.jar >result.txt

I am trying to join two commands together that I know work individually. 我正在尝试将两个命令连接在一起,我知道我单独工作。

Any help appreciated. 任何帮助赞赏。

您可以使用类似的东西在每个文件上执行命令:

find . -name "*.jar" -exec md5sum {} \; >result

This will also work to recursively hash all files in the current directory or sub-directories (thanks to my sysadmin!): 这也可以递归地散列当前目录或子目录中的所有文件(感谢我的sysadmin!):

md5sum $(find . -name '*.jar') > result.txt

The above will prepend "./" to the filename (without including the path). 以上将在文件名前添加“./”(不包括路径)。

Using the -exec suggestion from mux prepends "*" to the filename (again, without the path). 使用来自mux的-exec建议将“*”添加到文件名(再次,没有路径)。

The listed file order also differed between the two, but I am unqualified to say exactly why, since I'm a complete noob to bash scripting. 列出的文件顺序在两者之间也有所不同,但我没有资格确切地说明原因,因为我是一个完整的noob来bash脚本。

Edit: Forget the above regarding the prepend and full path, which was based on my experience running remotely on an HPC. 编辑:忘记上面关于前置和完整路径的内容,这是基于我在HPC上远程运行的经验。 I just ran my sysadmin's suggestion on my local Windows box using cygwin and got the full path, with "*./" prepended. 我刚刚使用cygwin在我的本地Windows机器上运行了我的系统管理员的建议并得到了完整的路径,前面加上“*。/”。 I'll need to use some other fanciness to dump the inconsistent path and prepending, to make the comparison easier. 我需要使用其他一些功能来转储不一致的路径和前置,以使比较更容易。 In short, YMMV. 简而言之,YMMV。

您还可以将结果传递给xargs

find . -name "*.jar" | xargs md5sum > result.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM