Linux命令行使用for循环和格式化结果 [英] Linux Command Line using for loop and formatting results

查看:874
本文介绍了Linux命令行使用for循环和格式化结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用一个命令行提供一定大小之间所有文件的列表,然后使用名称,md5具有和文件大小的格式设置文件.

How can I use one command line to provide a list of all files between a certain size and then format the file with name, md5 has and the file size.

示例输出应为

file1.***     MD5 value   size
file2.***     MD5 value   size etc.

我尝试了以下操作,但它在单独的行上显示了md5

Ive tried the following but it displays the md5 on a separate line

find 'directory' -size +30000c -size -50000c | 
while read filename 
   do ls -l "$filename" | awk '{print $9 "\t" $5}' 
   md5sum "$filename" | awk '{print $1}' 
done

它在单独的行上输出MD5的跟踪信号

It outputs the follow with the MD5 on a seperate line

file1.***   size
MD5

file2.***   size
MD5

推荐答案

您可以将rhash用于此简单任务

You can use rhash for this simple task

find dir/ -type f -size +30000c -size -50000c -exec rhash -p "%p %m %s\n" {} \;

  • -p以自定义格式打印
  • %p表示文件路径,%m表示md5sum,%s表示文件大小(以字节为单位)
    • -p prints in custom format
    • %p for file path, %m for md5sum and %s for file size in bytes
    • 这篇关于Linux命令行使用for循环和格式化结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆