在bash中循环行命令 [英] Loop a line command in bash
本文介绍了在bash中循环行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将如何循环此行以将所有jpg文件都打印到文本文件中?
How would I loop this line to print everything jpg to a text file??
stat --printf="%s" *.jpg >> results.txt
您还将如何根据文件大小打印result.txt?代码看起来如何?文件的确切大小为40318
How would you also be able to print results.txt based on a file size?? How would the code look?? The exact size of the file is 40318
推荐答案
您已经在打印所有* .jpg文件的结果.唯一的问题是,通过使用--printf="%s"
,您正在更改stat
的输出格式以仅打印尺寸(每行之间没有换行符或空格).
You already are printing the results for all *.jpg files. The only problem is that by using --printf="%s"
you are changing the output format of stat
to print only the size (without line breaks or spaces in between each item).
请尝试:
stat --printf="%s\n" *.jpg >> results.txt
# OR
stat -c "%s" *.jpg >> results.txt
要在文件大小旁边打印文件名,请尝试:
To print the filename next to the size, try:
stat --printf="%n %s\n" *.jpg >> results.txt
# OR
stat -c "%n %s" *.jpg >> results.txt
这篇关于在bash中循环行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文