2

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 Answers 2

2

You can do something like this:

du -sxh * | sort -rh | head -10 | xargs rm -fr $1
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much. Could you please explain what $1 will do ?
$1 is the input to the xargs received from the output generated from head
1

You can do,

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

1 Comment

where $1 is output of first one as input of second one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.