getting list of top space consuming files and remove it

时间:2016-04-07 10:40:12

标签: xargs rm du

I am using du -hsx * | sort -rh | head -10 to get top 10 space consuming files in directory. So I would like to know how to pass output of above command and delete those files. I know about xargs but I don't know how to incorporate it in my command, so any help would be appreciated ?

Thanks

2 个答案:

答案 0 :(得分:1)

You can do something like this:

du -sxh * | sort -rh | head -10 | xargs rm -fr $1

答案 1 :(得分:1)

你可以,

du -sxh * | sort -rh | head -10 > out
cat out | xargs rm -fr $1