[英]Bash script loop to count file size of all files in current directory?
Im very new to bash, and I have been given the task to write a bash script incorporating a loop that counts the byte size of all files in the current directory. 我对bash还是很陌生,我被赋予编写一个bash脚本的任务,该脚本包含一个循环,该循环对当前目录中所有文件的字节大小进行计数。
I want to use du but Ive been told he wants to see wc as the main command used. 我想使用du,但有人告诉我他想将wc用作主要命令。
As to how to make a loop accomplish these things, I'm unsure. 至于如何使循环完成这些事情,我不确定。 Can anyone give me an example or point me in the right direction?
谁能给我一个例子或指出正确的方向吗?
for fname in *; do
your-way-to-display-size-of-file "$fname"
done
You need to gather several bits of bash know-how 您需要收集一些bash专有技术
to loop over files 遍历文件
for filename in * .[^.]*
do
...
done
to use the output of one command in another 在另一个命令中使用一个命令的输出
command $(other_command ...)
to sum numbers in bash 用bash求和
count=$(($count + 1))
to count the number of bytes in a file with wc 用wc计算文件中的字节数
wc -c $filename
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.