我正在使用相同的find命令获取文件数和find大小,但当前正在运行find两次,如下所示。如何在一行中执行两个操作,并消除一次查找?
file_cnt[$i]=$(find $dir_name -type f -ctime +$ctime1 -ctime -$ctime2 | wc -l)
file_size[$i]=$(find $dir_name -type f -ctime +$ctime1 -ctime -$ctime2 | xargs --no-run-if-empty --max-procs=2 du -s | awk '{sum += $1} ; END {printf "%.2f", sum/1024**2}')发布于 2018-12-10 21:42:08
试试这样的东西
read "file_cnt[$i]" "file_size[$i]" << EOF
$(find $dir_name -type f -ctime +$ctime1 -ctime -$ctime2 | xargs --no-run-if-empty --max-procs=2 du -s | awk '{count++;sum += $1} ; END {printf "%d %.2f", count, sum/1024**2}')
EOF发布于 2019-01-09 18:31:18
我建议使用find来返回文件大小,使用awk来计算总和和文件数量:
$ find $dir_name -type f -ctime +$ctime1 -ctime -$ctime2 -printf "%s\n" | awk '{s+=$1}{print NR,s}'https://stackoverflow.com/questions/53700862
复制相似问题