[emdfqmm@nfwne ncndnkln]$ ll -h | grep "Oct" | grep "2018" | xargs du -ch
5.0G ./something
5.0G .
5.0G total
[emdfqmm@nfwne ncndnkln]$ ll -h | grep "Oct" | grep "2018" | wc -l
0
当它得到空输入时,它计算整个目录大小如何停止它
答案1
xargs
如果没有给出输入,可以选择不运行:
-r, --no-run-if-empty
If the standard input does not contain any nonblanks, do not run
the command. Normally, the command is run once even if there is
no input. This option is a GNU extension.
所以改用xargs -r du -ch
吧。
答案2
find
与以下一起使用-exec
:
month="Oct-2018";
find . -mindepth 1 -maxdepth 1 -newermt "01-$month -1 sec" -and -not -newermt "01-$month +1 month -1 sec" -exec du -ch {} \;
不过,不知怎的,我相信,你想要du -sh
而不是du -ch
.
看