This video is about xargs.
So xargs is used to build commands dynamically from the standard input.
Normally it gets its input from a pipe and it allows commands that don't support piped input to work with
other commands. Anyway, it's a little bit like what we have seen in find exec, but xarc is is faster
and more flexible than find exec for the simple reason that xarcs works on other commands as well.
If multiple arguments are passed through a command that supports one single argument
only, you can use N1 to process the arguments one by one.
So that means that you are not going to use echolisalinda, lori,
pipexargs user@ but echo lisa, linda, laurie, pipe xarx n1userad there are
some commands that are a bit problematic with xargs like ls.
So for that reason don't try to use xargs together with ls.
Better use find instead. Let's have a look at some examples.
So for the first example I'm going to create a couple of files.
Let's use touch one ten log.
So I now created a couple of files that
have the extension log and just to explain how
it works, I'm using LFS log on xargs RM
f and the result all these cells are gone.
Now this example is not so very powerful because you might wonder why didn't
you just use rmstar log? And yeah, that would have worked as well.
But to understand how xargs is taking input from a pipe, it's useful because
normally RM f needs an argument and this argument is provided dynamically by xargs.
Another example, let's do a sudo now.
You know what, let's do something else.
Ddif is dev0of is big
file 1bs is 125m, only
24. That also works.
So what is this command doing? Well, this command is creating a
file with the name bigfile1 and oops, I did it wrong.
I forgot to specify how many blocks it should copy. But hey, it did create a file
with the name big file1 and as you can see, this big file1 is really big.
Now I'm going to use find.type f size +100m followed by
xarcs. Well, on the slide I'm using MV to move it,
but here I better use RM F to remove it.
As a result, we don't have bakefile anymore. And let's do a quick df
h to verify that I still have 12 gigabytes available. Phew, that works.
Now let's use another one and this other one is
echo linda lisa laurie 5 sudo xrgs we need sudo
this time because I'm going to create some users.
N1 to user add sudo requires a sudo password. It does give an error on user
Linda because that user already existed. But users Lisa and Lori have successfully been created.
I can use a quick test to verify using til n3 on etc passwd that's showing the
last three lines in the passwd file showing that the users have indeed been successfully created.
That's xargs.