1 00:00:00,000 --> 00:00:09,480 [No audio] 2 00:00:09,480 --> 00:00:14,280 Finding files and directories. Oftentimes system 3 00:00:14,280 --> 00:00:18,570 administrators or system engineers or technicians, 4 00:00:18,570 --> 00:00:23,280 whoever the user of Linux is, they forget where 5 00:00:23,280 --> 00:00:26,730 files are located. Just like in Windows, when you 6 00:00:26,730 --> 00:00:29,430 want to find out find a file, you are given a 7 00:00:29,430 --> 00:00:33,000 little search box at the top of the window, and 8 00:00:33,000 --> 00:00:35,790 you type in the search and looks for its file. It 9 00:00:35,790 --> 00:00:38,640 takes a very long time, of course, in Windows, but 10 00:00:38,640 --> 00:00:43,500 in Linux, it's a lot faster and a lot easier. So 11 00:00:43,830 --> 00:00:47,760 there are two main commands that are used to find 12 00:00:47,760 --> 00:00:52,590 files and directories in your system. And the 13 00:00:52,590 --> 00:00:54,750 reason you need to find it, if you remember, I 14 00:00:54,750 --> 00:00:58,560 gave you an example of our closet. You go into our 15 00:00:58,560 --> 00:01:02,430 closet, you want to find a shirt that you haven't 16 00:01:02,430 --> 00:01:05,040 been worn for a long time and you don't know where 17 00:01:05,040 --> 00:01:08,310 you have it, which drawer or which shelf. You do need 18 00:01:08,310 --> 00:01:11,580 to have tools to look for those files, and those 19 00:01:11,580 --> 00:01:15,600 tools in Linux or find and locate. So we're going 20 00:01:15,600 --> 00:01:18,990 to use those commands in our Linux 21 00:01:18,990 --> 00:01:22,290 environment and do some exercises and see how they work. 22 00:01:22,290 --> 00:01:28,170 [No audio] 23 00:01:28,170 --> 00:01:31,800 So here we have our Linux machine, and let's find 24 00:01:31,800 --> 00:01:35,580 out where we are. We are in our home directory. 25 00:01:36,000 --> 00:01:41,670 And in our home directory we have files, different 26 00:01:41,670 --> 00:01:44,040 files and different directory. I wanted to go into 27 00:01:44,130 --> 00:01:47,220 seinfeld directory, and I want to see what's 28 00:01:47,220 --> 00:01:50,190 inside of it. Inside of it, there are different 29 00:01:50,190 --> 00:01:53,740 files called kramer, george, jerry, puddy, seinfeld-characters, 30 00:01:53,740 --> 00:01:55,650 all those different parts. Now what if 31 00:01:55,650 --> 00:02:00,540 you go back one step and you are in home 32 00:02:00,540 --> 00:02:03,660 directory, and here you thought that you 33 00:02:03,660 --> 00:02:07,230 created a file called kramer in this home 34 00:02:07,230 --> 00:02:09,449 directory but when you come in here, you don't see 35 00:02:09,449 --> 00:02:13,380 it. So you could either go into each directory one 36 00:02:13,380 --> 00:02:16,410 by one, do ls command and find it which is very 37 00:02:16,410 --> 00:02:19,140 cumbersome. You don't want to do it. So you could 38 00:02:19,140 --> 00:02:24,270 find it by the command find. The syntax 39 00:02:24,270 --> 00:02:27,180 of the command is find, and where do you want 40 00:02:27,180 --> 00:02:30,420 to find it. You could give a relative path which is 41 00:02:30,450 --> 00:02:34,650 dot which means in this current directory, start 42 00:02:34,650 --> 00:02:37,680 the search from this current directory, and this 43 00:02:37,680 --> 00:02:41,790 current directory is home/iafzal, so find dot 44 00:02:42,090 --> 00:02:51,000 dash name space "kramer", and 45 00:02:51,000 --> 00:02:54,180 you hit enter. It's going to tell you that the 46 00:02:54,180 --> 00:02:58,410 kramer file is inside of seinfeld directory and 47 00:02:58,410 --> 00:03:01,830 it's in there starting from this current 48 00:03:01,830 --> 00:03:04,290 directory. So this current directory has seinfeld 49 00:03:04,290 --> 00:03:07,470 directory, yes, of course. And now I know I created 50 00:03:07,470 --> 00:03:11,220 that kramer file in seinfeld. Okay, perfect. 51 00:03:11,910 --> 00:03:15,300 locate command works the same way. So you are in 52 00:03:15,300 --> 00:03:19,110 your home directory and you want to locate kramer 53 00:03:19,860 --> 00:03:24,150 This is telling you exactly where that file is. 54 00:03:24,150 --> 00:03:39,330 [No audio] 55 00:03:39,330 --> 00:03:44,730 find command is used sometimes to look for files 56 00:03:44,760 --> 00:03:48,000 in a very hierarchical way where you have tons of 57 00:03:48,000 --> 00:03:51,120 different directory, where locate is going to find 58 00:03:51,120 --> 00:03:56,880 you in a short searches. So if you want to find 59 00:03:57,120 --> 00:04:02,610 where, let's say our network file is where it's 60 00:04:02,640 --> 00:04:09,000 located. So if you see find slash because you want 61 00:04:09,000 --> 00:04:14,280 to find that network file from the root of the 62 00:04:14,280 --> 00:04:16,680 file system, because you don't know where that 63 00:04:16,709 --> 00:04:19,019 file is starting from which directory, so you will 64 00:04:19,019 --> 00:04:26,778 always start with root space dash name, comma "ifcfg" 65 00:04:26,778 --> 00:04:31,710 dash, and what is our interface. We don't know 66 00:04:31,710 --> 00:04:37,366 our interface so we'll just Ctrl C and we'll do ifconfig, 67 00:04:37,366 --> 00:04:40,800 and our interface enp0s3. So 68 00:04:40,800 --> 00:04:49,050 find slash name ifcfg, this is the 69 00:04:49,050 --> 00:04:53,250 file name of our interface, which we will cover by 70 00:04:53,250 --> 00:04:57,000 the way later. And we want to find it now we are 71 00:04:57,000 --> 00:04:59,040 getting all the Permission denied. Whoa, whoa, 72 00:04:59,040 --> 00:05:02,280 whoa, whoa. Okay okay, relax, relax. Why are 73 00:05:02,280 --> 00:05:05,250 we getting permission denied? Why didn't it find it? 74 00:05:05,880 --> 00:05:11,700 Hmm. Okay, I know why. And I'm sure you guys know 75 00:05:11,700 --> 00:05:15,840 why too, because you do not have permissions to go 76 00:05:15,840 --> 00:05:19,650 into certain directories. So, why because you are 77 00:05:19,650 --> 00:05:21,840 iafzal and who have permission to go into 78 00:05:21,840 --> 00:05:27,690 different directories. Tell me, root, yes, root has 79 00:05:27,690 --> 00:05:32,880 it. So you do su root, to become root, put in 80 00:05:32,880 --> 00:05:36,060 the password. Now you run that command find 81 00:05:37,350 --> 00:05:45,270 slash, from the beginning ifcfg dash enp, I 82 00:05:45,270 --> 00:05:51,180 always forget that, sorry. Okay, so find slash 83 00:05:51,450 --> 00:06:01,047 name, and ifcfg-enp0s3. 84 00:06:01,047 --> 00:06:03,630 And now I'm going to run it. Now it's going 85 00:06:03,630 --> 00:06:06,750 to go into every directory and look for it. The 86 00:06:06,750 --> 00:06:09,390 first one is just a run directory. I suppose this 87 00:06:09,390 --> 00:06:12,450 is just the process itself. So don't worry about 88 00:06:12,450 --> 00:06:15,660 it, you can ignore it. Second one, you'll see it 89 00:06:15,660 --> 00:06:19,470 found it. It is telling me this file that you're 90 00:06:19,470 --> 00:06:27,834 looking for is in /etc/sysconfig/network-scripts/ifcfg-enp0s3. 91 00:06:27,834 --> 00:06:33,540 If someone asks you, where is that file located as if 92 00:06:33,540 --> 00:06:35,970 it's in just a general question, or if it's an 93 00:06:36,000 --> 00:06:38,220 interview question, you know, the best way to 94 00:06:38,220 --> 00:06:42,450 answer it is I will run my find command or locate 95 00:06:42,450 --> 00:06:46,410 command to find where the file is located. So 96 00:06:46,410 --> 00:06:50,550 practice those two commands, run man on these 97 00:06:50,640 --> 00:06:54,540 commands, and look for different options that you 98 00:06:54,540 --> 00:06:58,830 could use for these commands and see how easy it 99 00:06:58,830 --> 00:07:00,442 could become for you. 100 00:07:00,442 --> 00:07:07,925 [No audio]