1
00:00:06,660 --> 00:00:08,849
In this video, we'll
talk about a find utility.

2
00:00:09,890 --> 00:00:13,880
The find utility can find
files based on multiple properties, like

3
00:00:13,880 --> 00:00:17,870
file names, but also username
or size, and much more.

4
00:00:18,789 --> 00:00:25,269
Find is the most efficient utility to find files, but
on large systems with many files, it may be slow.

5
00:00:26,780 --> 00:00:33,109
When combined with the exec option, specific commands can
be executed on the result of the find command.

6
00:00:33,750 --> 00:00:40,280
Let's check out some examples for your convenience.
I've listed the examples on the slide as well.

7
00:00:41,740 --> 00:00:48,545
So let me start by using find/name
hosts, which is doing what? Oh no, so

8
00:00:48,545 --> 00:00:55,350
many. Permission denied. Well, you know what,
I don't want to see these Permission denied.

9
00:00:55,770 --> 00:00:59,700
So I'm going to put sudo
in front of all of my

10
00:00:59,700 --> 00:01:03,630
find commands so that we don't
have any access permissions to files.

11
00:01:07,090 --> 00:01:10,930
There we can see still two
error messages, but these are to

12
00:01:10,930 --> 00:01:14,770
be ignored. We can see four
files that have the name hosts.

13
00:01:15,930 --> 00:01:21,129
Now, the thing is that when you use find,
the name that you specify is the exact file name.

14
00:01:21,650 --> 00:01:26,835
And if you want it to be
occurring in the file name, but not

15
00:01:26,835 --> 00:01:32,020
the exact file name, you might want
to use the star, the wildcard character.

16
00:01:32,700 --> 00:01:36,550
And here we can see
that. Now it also contains files

17
00:01:36,550 --> 00:01:40,400
like ghostscript, which does contain
hosts, but it's not the same.

18
00:01:42,359 --> 00:01:46,200
You can also use find
based on a user account.

19
00:01:47,319 --> 00:01:53,311
Now, I didn't create many users. Let
me quickly create a user user adlinda and

20
00:01:53,311 --> 00:01:59,304
then I can use sudo find user
lynda and there we can see all files

21
00:01:59,304 --> 00:02:05,296
that are owned by user. Linda, in
case you are wondering, how come you just

22
00:02:05,295 --> 00:02:11,287
created the user? Well, that is because
when you create a user, a home directory

23
00:02:11,288 --> 00:02:17,280
is created and some files are
copied into the user home directory.

24
00:02:19,000 --> 00:02:24,159
Now, find can also be used
on size, so sudo find minus size.

25
00:02:26,840 --> 00:02:31,539
So sudo find size
plus 200m, which is

26
00:02:31,539 --> 00:02:36,239
showing files that have
a size larger than

27
00:02:36,240 --> 00:02:40,939
200 megabytes. That's
not too many.

28
00:02:42,240 --> 00:02:44,219
And you can
find based on permissions.

29
00:02:44,770 --> 00:02:47,810
So sudo find
perm for three.

30
00:02:52,009 --> 00:02:52,580
Now, what
is this 4,000?

31
00:02:54,229 --> 00:02:59,789
Well, that is a search that makes sure that
you find files that have a 4 in the first

32
00:02:59,789 --> 00:03:05,349
permissions. For now, that doesn't make too much sense.
But later on, when we have learned about permissions, you

33
00:03:05,349 --> 00:03:10,909
will learn that this is for files that have
the set user ID permission, a potentially dangerous permission.

34
00:03:12,469 --> 00:03:16,199
Now, one very powerful feature of
the find command is that you can

35
00:03:16,199 --> 00:03:19,930
also run a command based on
the result of the find command.

36
00:03:20,629 --> 00:03:25,254
So sudo find user
lynda and let me

37
00:03:25,254 --> 00:03:29,879
first use a
exec LS l semicolon.

38
00:03:33,770 --> 00:03:37,900
So what is this doing? Well, it's
first finding files owned by user Linda.

39
00:03:38,500 --> 00:03:44,090
And on the result of the find
command, it is using the exec command.

40
00:03:44,770 --> 00:03:50,860
So it starts with exec and it ends with a
backslash semicolon. And the command to be executed is LS L.

41
00:03:52,819 --> 00:03:57,460
This is what it looks like.
Long listing of all these files.

42
00:03:58,789 --> 00:03:59,289
Is
that so?

43
00:04:00,340 --> 00:04:00,909
Look
at that.

44
00:04:01,610 --> 00:04:03,259
This is not
owned by you, Solinda.

45
00:04:04,400 --> 00:04:08,805
Well, you know what? I made an
error, but this is a nice error and

46
00:04:08,805 --> 00:04:13,210
that's why I didn't edit it out.
I use LS L without anything behind it.

47
00:04:13,969 --> 00:04:20,459
We need to put something behind it because without anything
behind it, it will just list files in the current directory.

48
00:04:21,310 --> 00:04:24,069
I was missing the
opening and closing curly braces.

49
00:04:25,329 --> 00:04:31,639
The curly braces refer to the result of the
find command. I only want to do an LS

50
00:04:31,639 --> 00:04:37,949
L on these valves that are owned by user
Linda. And as you can see, this result makes

51
00:04:37,949 --> 00:04:44,259
so much more sense based on that. We
can do so many powerful things with the exec.

52
00:04:44,560 --> 00:04:49,350
Let me use CP A for instance,
with the curly braces to root Linda.

53
00:04:53,800 --> 00:04:59,639
Here we are doing something that's probably not
going all right, I want to copy my

54
00:04:59,639 --> 00:05:05,480
valves into a directory with the name root
Linda. Guess what? That directory does not exist.

55
00:05:06,300 --> 00:05:07,459
You know what
I'm going to do?

56
00:05:07,959 --> 00:05:13,593
I'm using CTRL A to move my cursor
to the start of the command line and I'm

57
00:05:13,593 --> 00:05:19,226
creating the directory sudo mkdir root lynda and
then I'm using a semicolon. The semicolon is a

58
00:05:19,226 --> 00:05:24,860
command separator. So this is in fact
running two commands from one command command line.

59
00:05:25,759 --> 00:05:31,303
And there we get what? Well,
we get. Cannot override non directory root

60
00:05:31,303 --> 00:05:36,846
Linda Linda with directory home Linda.
I do understand that it's trying to

61
00:05:36,846 --> 00:05:42,389
copy directories as well, but I
never told it to do so.

62
00:05:42,740 --> 00:05:48,740
You know what one potentially
useful addition is minus type F.

63
00:05:49,759 --> 00:05:55,259
Because the command that we have just seen is because
of the fact that that it was trying to copy directories.

64
00:05:55,870 --> 00:05:59,850
I don't want to copy directories. I
want it to work on files only.

65
00:06:00,389 --> 00:06:03,389
Type F means that
it works on files only.

66
00:06:03,970 --> 00:06:10,149
Now we are getting a couple of the same
file. I know because I already did this beforehand.

67
00:06:11,069 --> 00:06:17,480
But it's showing some examples of the kind of
powerful things you can do with the find utility.
