1 00:00:06,660 --> 00:00:09,840 - In this video, we are going to talk about path names. 2 00:00:09,840 --> 00:00:12,180 So what is there to know about path names? 3 00:00:12,180 --> 00:00:15,210 Well, you can specify your paths in two ways. 4 00:00:15,210 --> 00:00:16,700 As an absolute path. 5 00:00:16,700 --> 00:00:18,990 An absolute path contains the full name 6 00:00:18,990 --> 00:00:21,123 from the root directory to a file. 7 00:00:22,290 --> 00:00:26,280 An example is /var/log/messages. 8 00:00:26,280 --> 00:00:28,230 The nice thing about an absolute path 9 00:00:28,230 --> 00:00:31,890 is that it is very clear what you are referring to. 10 00:00:31,890 --> 00:00:33,840 Can't be any doubt about it. 11 00:00:33,840 --> 00:00:35,850 But sometimes it's too much typing. 12 00:00:35,850 --> 00:00:38,250 And for that reason, you might be better off 13 00:00:38,250 --> 00:00:40,320 using a relative path. 14 00:00:40,320 --> 00:00:43,110 Relative path is related to the current directory, 15 00:00:43,110 --> 00:00:47,130 and it contains the rest that is needed to get to a file, 16 00:00:47,130 --> 00:00:49,950 like log/messages, which will work 17 00:00:49,950 --> 00:00:52,800 if the current directory is set to /var. 18 00:00:52,800 --> 00:00:55,950 Now in relative paths, you can use dot dot 19 00:00:55,950 --> 00:00:57,960 for one directory up. 20 00:00:57,960 --> 00:01:01,143 If the current directory is /var/cache, for instance, 21 00:01:01,143 --> 00:01:06,143 ../log/messages points to /var/log/messages file. 22 00:01:07,560 --> 00:01:10,860 But if I may give you a tip, use absolute paths 23 00:01:10,860 --> 00:01:12,600 to avoid confusion. 24 00:01:12,600 --> 00:01:14,370 Now before I'm going to demonstrate, 25 00:01:14,370 --> 00:01:15,690 let me make a quick drawing 26 00:01:15,690 --> 00:01:19,020 so that I can visualize what exactly it is 27 00:01:19,020 --> 00:01:20,253 that we are going to do. 28 00:01:23,100 --> 00:01:26,490 In this video, I would like to visualize these relative 29 00:01:26,490 --> 00:01:28,230 and absolute path names. 30 00:01:28,230 --> 00:01:31,440 So let's draw a small directory structure. 31 00:01:31,440 --> 00:01:33,120 Start with the root directory. 32 00:01:33,120 --> 00:01:35,043 In the root directory, we have etc, 33 00:01:37,860 --> 00:01:38,970 we have tmp, 34 00:01:38,970 --> 00:01:42,513 and in tmp we have data. 35 00:01:43,380 --> 00:01:48,090 Okay, so let's imagine that in etc, we have this file, 36 00:01:48,090 --> 00:01:51,003 and the name of this file is passwd. 37 00:01:52,020 --> 00:01:54,630 And in tmp, we have this file, 38 00:01:54,630 --> 00:01:57,280 and the name of this file is hosts 39 00:01:58,290 --> 00:02:00,300 because we copied it over here. 40 00:02:00,300 --> 00:02:02,160 Now just imagine that we are currently 41 00:02:02,160 --> 00:02:04,500 in the data directory. 42 00:02:04,500 --> 00:02:07,380 The data directory, represented by a dot. 43 00:02:07,380 --> 00:02:09,420 The dot is the current directory. 44 00:02:09,420 --> 00:02:14,160 And I want to copy this file up to this location. 45 00:02:14,160 --> 00:02:15,750 And I'm right here. 46 00:02:15,750 --> 00:02:17,310 Then what can we do? 47 00:02:17,310 --> 00:02:20,490 Well, we can use these relative file names 48 00:02:20,490 --> 00:02:24,060 and use a command like cp dot dot. 49 00:02:24,060 --> 00:02:26,880 If you use dot dot, then it brings us up 50 00:02:26,880 --> 00:02:29,670 from the data directory to the tmp directory 51 00:02:29,670 --> 00:02:32,070 as our current directory. 52 00:02:32,070 --> 00:02:35,490 And if I want to use relative file names to copy it, 53 00:02:35,490 --> 00:02:37,080 I need to go up one more level. 54 00:02:37,080 --> 00:02:40,620 So another dot dot, then I get into the root directory, 55 00:02:40,620 --> 00:02:44,567 and then I can specify /etc/passwd to dot. 56 00:02:47,490 --> 00:02:50,220 But hey, is that the most accurate way of doing it? 57 00:02:50,220 --> 00:02:53,220 Well, I don't think so, because in this way 58 00:02:53,220 --> 00:02:58,220 you probably would be better off using absolute file names. 59 00:02:58,470 --> 00:03:02,040 I mean, what's the sense if you go all the way down 60 00:03:02,040 --> 00:03:04,230 to the root directory anyway? 61 00:03:04,230 --> 00:03:07,980 It would make sense if you want to copy over the file hosts 62 00:03:07,980 --> 00:03:09,450 to the current directory. 63 00:03:09,450 --> 00:03:13,770 In that case, you can use cp.. to go up one level, 64 00:03:13,770 --> 00:03:15,030 that brings you here. 65 00:03:15,030 --> 00:03:17,580 Then you can refer to the file hosts, 66 00:03:17,580 --> 00:03:21,570 and then you can copy it to the dot directory. 67 00:03:21,570 --> 00:03:24,120 And that's a little demo of how you can work 68 00:03:24,120 --> 00:03:26,340 with these absolute and relative file names. 69 00:03:26,340 --> 00:03:28,890 Let me show you what this looks like on a computer. 70 00:03:31,350 --> 00:03:34,740 All right, I am going to create the directory data. 71 00:03:34,740 --> 00:03:36,480 Notice that this is a relative path. 72 00:03:36,480 --> 00:03:39,570 I'm in the tmp directory, and I'm creating data. 73 00:03:39,570 --> 00:03:41,343 That will create a subdirectory. 74 00:03:42,480 --> 00:03:47,480 And I am going to copy /etc/hosts to dot 75 00:03:47,610 --> 00:03:51,000 so that in the data directory we have /etc/hosts. 76 00:03:51,000 --> 00:03:56,000 And I'm going to copy /etc/passwd to /data. 77 00:03:56,580 --> 00:03:57,540 Is that what I want? 78 00:03:57,540 --> 00:04:00,353 No, because I want to create it to the subdirectory 79 00:04:00,353 --> 00:04:02,610 in this tmp directory. 80 00:04:02,610 --> 00:04:06,330 So I need a relative path, and this is the relative path. 81 00:04:06,330 --> 00:04:08,820 Now I'm going in the data directory, 82 00:04:08,820 --> 00:04:12,480 and in the data directory I see my passwd. 83 00:04:12,480 --> 00:04:15,000 Pwd might be convenient as well. 84 00:04:15,000 --> 00:04:18,150 That is where you can see what exactly is going on. 85 00:04:18,150 --> 00:04:21,780 So if I use cp passwd to dot dot, 86 00:04:21,780 --> 00:04:23,640 can you guess what is going to happen? 87 00:04:23,640 --> 00:04:27,240 I'm going to copy passwd to one level up. 88 00:04:27,240 --> 00:04:30,300 And if I want to verify, I'm using ls.., 89 00:04:30,300 --> 00:04:33,210 and ls.. is showing a lot of stuff, 90 00:04:33,210 --> 00:04:36,270 including this data directory right here, 91 00:04:36,270 --> 00:04:40,440 and this passwd directory right here. 92 00:04:40,440 --> 00:04:44,073 And that is how you use absolute and relative path names.