Rahul
Rahul

Reputation: 418

getting list of top space consuming files and remove it

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

Upvotes: 2

Views: 411

Answers (2)

sudhir kumar mishra
sudhir kumar mishra

Reputation: 116

You can do,

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

Upvotes: 1

Sandeep Sukhija
Sandeep Sukhija

Reputation: 1176

You can do something like this:

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

Upvotes: 2

Related Questions