[Intro Music]
Now you know what is 'xargs' command,
and how you could use it with
piping. Now, let's suppose that we
have following task. We need to find
all directories that have "kernel"
somewhere in their names; and
afterwards we want to list all
files and directories in those
found directories. For that, we can
use 'ls' command combined with 'find'
command. First we'll find all
directories that contain somewhere
"kernel'; and afterwards we will
execute 'ls' command. Let's try to use
an 'exec' option in 'find' command. All
right. 'find', and let's look for such
folders in all folders, here will be
absolute path to root folder,
'/'. Next, I am looking for
folders that have somewhere "kernel"
like so, here will be '-name' option.
Next, I say that I want to search
only for directories '-type d'.
Next, comes 'exec' option, and here we
will execute 'ls' command that will
list all files and folders inside
of the found directories. 'exec ls
-l', we'll say; here will be also
'--color' option in order to see color
output; here will be pair of curly
braces; and in this case 'ls' command
will be run multiple times
depending on the quantity of the
found directories. And finally, it
will be a '\;'. And
it will be last argument for 'exec'
option. Here are actually all
arguments that will be used for
'-exec' option. All right, let's
press Enter, and see results. And
actually, I see such sections as
this one, this one, let me scroll a
bit up, here was one more large
section, and so on. Different
sections, one section per found
folder. Actually, let me remove
temporarily this '-exec' part, like
so, and execute it without '-exec'
option. And you see that in my
case, I have found the 1, 2, 3, 5 folders
that have "kernel" somewhere in their
name. And here you see all paths to
those folders - '/etc/kernel',
'proc/sys/kernel', and so on. And
actually here we see contents of
every such folder. For example,
let's list files and folders here
in this directory. Let me copy it,
paste, and I see same result as I
have seen here in this section. But
notice that in this output, we
don't see actually path to every
directory we are currently
processing. Recap that in this
command, let me go back to it, each
found directory will be sent as
argument here to 'ls -l --color'
command. Alright, now let's
try to use pipe operator and 'xargs'
command in order to perform same
action. I'll simply remove this
part with 'exec' operator; then I'll
add pipe, '|' operator, here will be
'xargs', like so; next, will be 'ls -
l'; and '--color' option.
Let's execute this command now and
see results. And now I see that all
files and folders of every found
directory are grouped per
path. For example, here I see files
and folders located in this
path. There is one file 'uevent',
and one folder 'parameters'. Same
I see for other directories. For
example, '/sys/kernel', '/root/etc-
backup-2/kernel' and so on. And
that means that now we see actually
result that differ from the
results that we have received with
'exec' option for 'find' command. And
actually here what happened? We
send results of 'find' command as
arguments using 'xargs' command to
this command; and this command has
executed actually multiple times,
in this case five times. And we
have seen results grouped by
specific directory name like, '/etc/kernel',
'/proc/sys/kernel', and so on.
That's how you could combine the
'find' command, pipe, '|' operator, and
'xargs' command. Alright guys, that's
all for this lecture. I hope you
enjoyed this example. And now you
understand how to use pipe, 'xargs',
'find' and other comments. And that's
all for 'find' command. I have given
you some examples. 'find' command is
very useful; and it has many, many
different options; and I hope
you'll explore some additional
options on your own. Now, let's go
on, and next let's talk about
compression in Linux, and I'll
explain you how to zip and unzip
different files and folders. I'll
see you next. Bye-Bye.
[no audio]