Xargs- concept, workings and application

Can anyone explin ‘Xargs’ for bash to me.
I am a learning how to code from the open sources available to me.

THANK YOU!

The idea behind xargs is to “execute on arguments”, so you give it a command to run but with something missing, then you give it the missing arguments as a list in some form. It’s basically a way to loop a command over a bunch of files or other arguments. I typically use it when the number of files is too large, so let’s say I have a ton of files to delete, I could do:

find . -name “badfiles.*” -print | xargs rm

The only thing is this is kind of useless because find supports this with -exec:

find . -name “badfiles.*” -exec rm {} ;

But, play around with it not using rm. Try using xargs ls to see the different effects.