The simplest use case for xargs is that you have a list of filenames and you want to feed that list to a command that only accepts filenames as CLI parameters:
I.e., 'find' generates a list of filenames.
But 'stat' (for example) only accepts file names as parameters on the command line.
You combine these two using 'xargs':
find -type f -print0 | xargs -0 stat --format="%y\t%n"
And you get an output of human readable modification times, a tab, the filename and a newline.
Note, the "-print0" to find instructs find to output null terminated filenames, and the -0 to xargs instructs xargs to expect to receive null terminated filenames. These switches (they may be specific to GNU coreutils) allow for handling filenames with any possible character in them correctly (i.e., spaces cause no troubles).
For this use case, remembering how/when to use xargs is easy. The more esoteric usages are the ones where "man xargs" is often handy.
I.e., 'find' generates a list of filenames.
But 'stat' (for example) only accepts file names as parameters on the command line.
You combine these two using 'xargs':
find -type f -print0 | xargs -0 stat --format="%y\t%n"
And you get an output of human readable modification times, a tab, the filename and a newline.
Note, the "-print0" to find instructs find to output null terminated filenames, and the -0 to xargs instructs xargs to expect to receive null terminated filenames. These switches (they may be specific to GNU coreutils) allow for handling filenames with any possible character in them correctly (i.e., spaces cause no troubles).
For this use case, remembering how/when to use xargs is easy. The more esoteric usages are the ones where "man xargs" is often handy.