1
00:00:00,690 --> 00:00:02,520
There will be times in Linus where you create a file

2
00:00:02,520 --> 00:00:05,850
and maybe you forget where the directory was.

3
00:00:05,850 --> 00:00:07,620
Sometimes you need to find log files

4
00:00:07,620 --> 00:00:11,673
or locations of different commands, anything.

5
00:00:12,840 --> 00:00:14,760
Linux comes with a lot of different commands

6
00:00:14,760 --> 00:00:18,600
that will allow you to execute these searches.

7
00:00:18,600 --> 00:00:20,610
So the first one I want to look at is locate,

8
00:00:20,610 --> 00:00:22,200
just really quick.

9
00:00:22,200 --> 00:00:25,053
We're just trying to locate anything relative to backup.

10
00:00:27,510 --> 00:00:30,870
And we see it gives us a huge list

11
00:00:30,870 --> 00:00:34,770
of any file name that has the word backup in it.

12
00:00:34,770 --> 00:00:37,020
And there's different options with that, right?

13
00:00:37,020 --> 00:00:40,023
We can make sure that this is case insensitive.

14
00:00:41,040 --> 00:00:42,243
So do I.

15
00:00:44,760 --> 00:00:46,791
Another thing we can do is,

16
00:00:46,791 --> 00:00:49,320
make sure that we actually just get a count.

17
00:00:49,320 --> 00:00:50,823
We just want to know how many.

18
00:00:52,380 --> 00:00:54,660
Now it gives us a number there.

19
00:00:54,660 --> 00:00:56,850
Now, the one I'm going to focus on the most today

20
00:00:56,850 --> 00:00:58,530
is the find command.

21
00:00:58,530 --> 00:01:01,920
This is clearly the most powerful one of them all.

22
00:01:01,920 --> 00:01:06,000
This allows us to do any structure that we like.

23
00:01:06,000 --> 00:01:08,700
To locate, we can't pick the file directory

24
00:01:08,700 --> 00:01:09,533
that we're looking into,

25
00:01:09,533 --> 00:01:11,610
it's just going to search the whole system.

26
00:01:11,610 --> 00:01:13,020
This allows us to search,

27
00:01:13,020 --> 00:01:16,500
if we're looking for a type of directory, type of file,

28
00:01:16,500 --> 00:01:18,450
just a lot of different options for us.

29
00:01:20,340 --> 00:01:21,540
So you see on this one,

30
00:01:21,540 --> 00:01:24,120
we're looking for a directory with anything

31
00:01:24,120 --> 00:01:26,670
with the name log but only directories.

32
00:01:26,670 --> 00:01:28,830
So it starts from the route directory,

33
00:01:28,830 --> 00:01:31,770
and it recursively searches every sub-directory

34
00:01:31,770 --> 00:01:34,863
for anything with log, as a directory name.

35
00:01:36,180 --> 00:01:37,500
Next, we're going to do the same thing,

36
00:01:37,500 --> 00:01:39,840
but we're going to look for a file.

37
00:01:39,840 --> 00:01:41,970
Starting from the route directory,

38
00:01:41,970 --> 00:01:43,920
so we got to do the type, it's going to be file,

39
00:01:43,920 --> 00:01:45,370
that's what the F stands for,

40
00:01:46,230 --> 00:01:48,153
the name from the messages.

41
00:01:50,040 --> 00:01:52,440
And now we see we have a file named messages

42
00:01:52,440 --> 00:01:54,663
under the VAR log sub directory.

43
00:01:56,430 --> 00:02:00,240
We can also look up files by certain sizes.

44
00:02:00,240 --> 00:02:02,130
For example, we're going to use it one more time,

45
00:02:02,130 --> 00:02:04,410
but we're going to look up any file,

46
00:02:04,410 --> 00:02:06,450
in this particular file location,

47
00:02:06,450 --> 00:02:07,950
so we're going to use the VAR log,

48
00:02:07,950 --> 00:02:10,113
that's larger than a hundred kilobytes.

49
00:02:11,280 --> 00:02:12,483
Okay. So let's do this.

50
00:02:15,630 --> 00:02:17,130
Type: it's going to be a file.

51
00:02:18,390 --> 00:02:19,223
Strings.

52
00:02:24,300 --> 00:02:25,680
So this gives us complete list

53
00:02:25,680 --> 00:02:28,800
of every file that's larger than a hundred kilobytes.

54
00:02:28,800 --> 00:02:31,380
And now we can test this out just by making sure.

55
00:02:31,380 --> 00:02:33,483
So we'll, let's take this out,

56
00:02:35,250 --> 00:02:36,183
Make it readable.

57
00:02:42,270 --> 00:02:46,290
And now we see this particular file is 287 kilobytes.

58
00:02:46,290 --> 00:02:47,890
If you want to just test one more.

59
00:02:49,740 --> 00:02:50,763
For good measure.

60
00:02:53,580 --> 00:02:55,563
Again, this one is 321 kilobytes.

61
00:02:56,640 --> 00:02:58,950
Now, along with sizes, you're also able

62
00:02:58,950 --> 00:03:01,770
to search for things that have been updated

63
00:03:01,770 --> 00:03:04,230
within a certain amount of time passing.

64
00:03:04,230 --> 00:03:06,040
So we're going to look for a type

65
00:03:07,078 --> 00:03:09,828
of file that's been updated within the last 30 minutes.

66
00:03:10,710 --> 00:03:12,900
So again, we'll look in the same directory.

67
00:03:12,900 --> 00:03:15,663
Log for a file,

68
00:03:17,700 --> 00:03:19,710
and then we're going to look for right here

69
00:03:22,770 --> 00:03:23,793
30 minutes.

70
00:03:25,950 --> 00:03:28,110
So all of these files have been updated

71
00:03:28,110 --> 00:03:29,643
within the past 30 minutes.

72
00:03:31,230 --> 00:03:33,173
Again, we're just going to verify this.

73
00:03:34,680 --> 00:03:37,323
Look up for our log.

74
00:03:38,652 --> 00:03:40,143
Let's just do the secure.

75
00:03:41,850 --> 00:03:43,923
Now it's updated at 12:40.

76
00:03:45,000 --> 00:03:46,770
And if you look at the top of my screen,

77
00:03:46,770 --> 00:03:49,020
you'll see that it's currently 12:49,

78
00:03:49,020 --> 00:03:50,170
so that's within range.

79
00:03:51,180 --> 00:03:52,800
You can also look for an either

80
00:03:52,800 --> 00:03:55,620
or type of clause attached to this command.

81
00:03:55,620 --> 00:04:00,513
So we're going to look for a file in our log.

82
00:04:04,080 --> 00:04:05,580
We wanted it to either be zero

83
00:04:08,130 --> 00:04:13,130
or is sized to be greater than a hundred kilobytes,

84
00:04:16,649 --> 00:04:20,343
and last been updated within the last 30 minutes.

85
00:04:24,090 --> 00:04:27,600
So this search function accomplishes all of these,

86
00:04:27,600 --> 00:04:28,920
and we're just going to verify one of these.

87
00:04:28,920 --> 00:04:31,050
So I'm going to list this out really quick.

88
00:04:31,050 --> 00:04:35,580
The list command, use the VAR log, just file.

89
00:04:37,320 --> 00:04:39,090
And we can see this was one that's selected

90
00:04:39,090 --> 00:04:41,190
because it's an empty file.

91
00:04:41,190 --> 00:04:42,510
Again so we just went over a few

92
00:04:42,510 --> 00:04:44,580
of the search commands in Linux.

93
00:04:44,580 --> 00:04:47,400
Now the locate command requires the database to be updated

94
00:04:47,400 --> 00:04:50,550
in order to perform accurate searches, but the font is not.

95
00:04:50,550 --> 00:04:52,260
And the font also allows us

96
00:04:52,260 --> 00:04:54,210
to search particular directories.

97
00:04:54,210 --> 00:04:57,240
So it has a lot of advantages over the locate

98
00:04:57,240 --> 00:04:59,820
but the locate can be faster, but of course it

99
00:04:59,820 --> 00:05:04,820
won't represent the entire disc versus the find command.

100
00:05:05,250 --> 00:05:07,050
And I'll see you in the next lesson.

