在ls bash输出中添加md5sum

Arm*_*man 4 bash shell find

我正在尝试查找文件并将其md5sum添加到表中.

find /store/01 -name "*.fits" -exec chmod -x+r {} \; -exec ls -l {} \; | tee ALL_FILES.LOG
Run Code Online (Sandbox Code Playgroud)

如何在ls -l输出中添加文件的md5sum?

我想让它输出ls -l一个额外的md5sum结果列

例如:

-rw-r--r-- 1 data user 221790 Jul 28 15:01 381dc9fc26082828ddbb46a5b8b55c03 myfile.fits 
Run Code Online (Sandbox Code Playgroud)

hmo*_*liu 6

这个衬垫可以做你想要的(通过添加/store/01 -name "*.fits" -exec chmod -x+r {} \;代替 . -type f我的例子来编辑查找搜索以满足你的需求):

$ find . -type f -exec sh -c 'printf "%s %s \n" "$(ls -l $1)" "$(md5sum $1)"' '' '{}' '{}' \;
Run Code Online (Sandbox Code Playgroud)

例:

/etc/samba$ find . -type f -exec sh -c 'printf "%s %s \n" "$(ls -l $1)" "$(md5sum  $1)"' '' '{}' '{}' \; 
-rw-r--r-- 1 root root 8 2010-03-09 02:03 ./gdbcommands 898c523d1c11feeac45538a65d00c838  ./gdbcommands 
-rw-r--r-- 1 root root 12464 2011-05-20 11:28 ./smb.conf 81ec21c32bb100e0855b96b0944d7b51  ./smb.conf 
-rw-r--r-- 1 root root 0 2011-06-27 10:57 ./dhcp.conf d41d8cd98f00b204e9800998ecf8427e  ./dhcp.conf 
Run Code Online (Sandbox Code Playgroud)

要获得所需的输出,可以删除字段$ 8,如下所示

/etc/samba$ find . -type f -exec sh -c 'printf "%s %s \n" "$(ls -l $1)" "$(md5sum  $1)"' '' '{}' '{}' \; | awk '{$8=""; print $0}'
-rw-r--r-- 1 root root 8 2010-03-09 02:03  898c523d1c11feeac45538a65d00c838 ./gdbcommands
-rw-r--r-- 1 root root 12464 2011-05-20 11:28  81ec21c32bb100e0855b96b0944d7b51 ./smb.conf
-rw-r--r-- 1 root root 0 2011-06-27 10:57  d41d8cd98f00b204e9800998ecf8427e ./dhcp.conf
Run Code Online (Sandbox Code Playgroud)

HTH