0 1 00:00:00,900 --> 00:00:01,140 All right. 1 2 00:00:01,140 --> 00:00:09,600 So in this lesson, I want to introduce you to directory creation, file creation, and directory manipulation. 2 3 00:00:09,600 --> 00:00:13,520 And we're going to be doing all of this inside the command line just with our keyboards. 3 4 00:00:13,530 --> 00:00:21,750 S,o again, right now I'm starting in my root directory over him and I am going to create a new folder 4 5 00:00:22,110 --> 00:00:26,750 right here. So, obviously, I can go through the right click. 5 6 00:00:26,780 --> 00:00:28,470 New Folder all of that. 6 7 00:00:28,530 --> 00:00:30,630 But we are pro developers now, 7 8 00:00:30,660 --> 00:00:32,900 so we're going to get used to using the command line. 8 9 00:00:33,000 --> 00:00:36,820 So the command is mkdir or make directory, 9 10 00:00:37,110 --> 00:00:39,630 and then we're going to give our directory a name. 10 11 00:00:39,630 --> 00:00:41,750 So let's just call it Angela, 11 12 00:00:41,880 --> 00:00:42,730 right? 12 13 00:00:42,810 --> 00:00:47,430 And you can see, there you go, pops up a new folder called Angela. 13 14 00:00:47,640 --> 00:00:59,280 Now, let's cd into this new directory. And you can see that if I click on here or if I use "ls," there's 14 15 00:00:59,370 --> 00:01:02,800 absolutely nothing in there, it's a empty folder. 15 16 00:01:03,150 --> 00:01:05,750 So what if I wanted to create a file? 16 17 00:01:05,790 --> 00:01:13,710 So in our graphical user interface, I could say open up an application like TextEdit, and I could make 17 18 00:01:13,710 --> 00:01:19,930 a file and write something in it, and then save it inside my new directories. 18 19 00:01:19,950 --> 00:01:25,470 So I would have to do a little bit of navigating in order to get there, and then I have to give my file 19 20 00:01:25,470 --> 00:01:26,360 a name. 20 21 00:01:26,400 --> 00:01:28,700 Let's call it Text and hit Save. 21 22 00:01:28,890 --> 00:01:31,730 So, now we have to exit the application. 22 23 00:01:31,740 --> 00:01:40,500 And after all of that work, I've got a text file. And if we do "ls," now, you can see that Text.rtf exists. 23 24 00:01:40,500 --> 00:01:46,950 But if you want to do the same thing using the command line, then it's as simple as simply typing "touch" 24 25 00:01:47,130 --> 00:01:48,550 to create a new file, 25 26 00:01:48,710 --> 00:01:53,670 then we're going to specify the name of the file, let's call it Text2, and then we give an extension .txt. 26 27 00:01:53,720 --> 00:02:00,130 And you can open in either by double clicking on it, which is what we're used to, 27 28 00:02:00,150 --> 00:02:10,080 or you can simply write open Text2, and it will open it using the default application which is TextEdit 28 29 00:02:10,080 --> 00:02:17,490 in a Mac. Now, you can specify which application you want to open this file in. 29 30 00:02:17,660 --> 00:02:22,430 And all you have to do is, say, the "open," and you're going to use the -a flag, 30 31 00:02:22,550 --> 00:02:26,570 then you're going to specify the application that you want to use. 31 32 00:02:26,570 --> 00:02:33,500 So let's say that we want to open it inside Atom, so I can write Atom, and then I can specify the 32 33 00:02:33,790 --> 00:02:38,840 file that I want to open, so Text2.txt, and hit enter. 33 34 00:02:38,930 --> 00:02:44,690 And it will open up the Atom application that I've got, and then open up my files for me to be able 34 35 00:02:44,690 --> 00:02:45,350 to edit. 35 36 00:02:45,350 --> 00:02:52,640 So what if you wanted to delete files inside the command line? So currently, I'm inside the Angela folder 36 37 00:02:52,940 --> 00:02:57,280 and there are two files, and I want to delete 37 38 00:02:57,320 --> 00:02:58,260 my Text.rtf. 38 39 00:02:58,520 --> 00:03:04,540 So then all you need to do is just use "rm"command which removes files. 39 40 00:03:04,730 --> 00:03:07,300 If you type the command as is, so just "rm," 40 41 00:03:07,550 --> 00:03:13,240 and then we're going to specify Text.rtf to remove. 41 42 00:03:13,280 --> 00:03:14,770 And once I hit enter, 42 43 00:03:14,900 --> 00:03:18,230 you'll see it disappear also in the Finder as well. 43 44 00:03:18,230 --> 00:03:21,690 Now, what if I want to remove all the files inside a folder? 44 45 00:03:21,800 --> 00:03:26,960 So let's create some more text files. 45 46 00:03:28,010 --> 00:03:35,560 So let's call it Text.txt, and then let's create Text 3.txt. 46 47 00:03:35,570 --> 00:03:41,030 So now I've got Text, Text2, Text3. A little bit of a tongue twister there. 47 48 00:03:41,580 --> 00:03:43,450 And I want to remove all of them. 48 49 00:03:43,460 --> 00:03:46,660 So to do that, all you have to do is just hit-- 49 50 00:03:46,820 --> 00:03:51,430 So to do that, you have to be inside the directory that you want to remove all the files from. 50 51 00:03:51,590 --> 00:03:58,150 And now I want to remove all of them in one go without having to type remove Text.txt, et cetera. 51 52 00:03:58,160 --> 00:04:05,210 So, again, we're using the remove command and then we're simply going to use the asterisk as a wildcard which 52 53 00:04:05,210 --> 00:04:08,400 matches everything that has every single name. 53 54 00:04:08,450 --> 00:04:14,890 And now if I hit enter, you can see that all my three files inside my current directory are removed. 54 55 00:04:14,930 --> 00:04:19,640 So do you remember in the beginning of this module, we mentioned that using the command line gives you 55 56 00:04:19,640 --> 00:04:21,780 more power, more control. 56 57 00:04:21,830 --> 00:04:28,850 And as we all know, with great power comes great responsibility, and that means that you have to be careful 57 58 00:04:29,060 --> 00:04:35,300 when using certain commands because the graphical user interface isn't there to protect you. 58 59 00:04:35,510 --> 00:04:42,500 So, for example, if you were not inside the directory that you wanted to delete, say, if you were inside 59 60 00:04:42,560 --> 00:04:49,570 your root directory and, you know, trying to remove all the files inside your root directory, 60 61 00:04:49,730 --> 00:04:52,220 then it's probably not such a great idea. 61 62 00:04:52,400 --> 00:04:59,090 So always check which location you're in before you're doing some of these destructive commands. 62 63 00:04:59,090 --> 00:05:05,570 Now, if you're here, now if you're inside your root directory and you tried to do remove--and you tried 63 64 00:05:05,570 --> 00:05:12,020 to do remove star, nothing bad is actually going to happen, because there aren't any files that are inside 64 65 00:05:12,020 --> 00:05:12,760 this directory, 65 66 00:05:12,770 --> 00:05:17,160 there's only folders. And to remove folders or remove directories, 66 67 00:05:17,180 --> 00:05:18,730 there's a different command. 67 68 00:05:18,920 --> 00:05:25,710 So, now I want to remove this Angela folder that I've created and I'm inside the right place to do it, 68 69 00:05:25,730 --> 00:05:32,290 I'm inside my root directory which is at this level. And, again, always check where you are 69 70 00:05:32,300 --> 00:05:36,020 by using the "ls" command. You can see that I am at this level. 70 71 00:05:36,110 --> 00:05:44,330 So, now I want to remove this Angela directory and if I just simply write remove Angela, and I hit enter, 71 72 00:05:44,420 --> 00:05:47,420 you can see it says that Angela is a directory. 72 73 00:05:47,510 --> 00:05:51,370 So this remove command by itself is not going to work. 73 74 00:05:51,380 --> 00:05:56,590 So to do it, we actually have to add a flag which is the -r flag. 74 75 00:05:56,630 --> 00:05:59,570 So this allows you to remove a directory. 75 76 00:05:59,750 --> 00:06:01,880 So, now let's try that again. 76 77 00:06:01,920 --> 00:06:02,270 Remove -r, 77 78 00:06:02,330 --> 00:06:04,800 and then we're going to use the Angela directory. 78 79 00:06:04,910 --> 00:06:11,420 And if we watch over here and I hit enter, you can see that that directory is now gone including all 79 80 00:06:11,420 --> 00:06:18,590 the files that it held, all the folders that are inside the Angela folder, and it removes all of its child 80 81 00:06:18,590 --> 00:06:19,670 components. 81 82 00:06:19,670 --> 00:06:22,760 So, again, these are destructive commands. 82 83 00:06:22,760 --> 00:06:24,860 Be really careful when you're using them. 83 84 00:06:24,860 --> 00:06:33,200 And in fact, there's a pretty hilarious bit of internet history which is where somebody submitted a question 84 85 00:06:33,530 --> 00:06:37,440 to StackExchange serverfault which is similar to StackOverflow, 85 86 00:06:37,460 --> 00:06:40,170 but it's more for assistant admin and network admins. 86 87 00:06:40,190 --> 00:06:43,990 So what he said was "Monday morning mistake," 87 88 00:06:44,240 --> 00:06:50,570 he used the sudo command which stands for super user do, which uses your admin privileges to basically 88 89 00:06:50,570 --> 00:06:57,170 allow you to do things that are, probably, a little bit dangerous, and use the remove command, and then the 89 90 00:06:57,230 --> 00:06:58,100 "-rf" flag. 90 91 00:06:58,100 --> 00:07:03,890 So we've already seen the "-r" which allows you to remove entire directories and all the folders and 91 92 00:07:03,890 --> 00:07:06,180 all the child folders it contained. 92 93 00:07:06,200 --> 00:07:11,660 He also used the "f" flag which stands for force. So this doesn't ask you for a confirmation. 93 94 00:07:12,070 --> 00:07:17,530 And then the very last thing which is something that you should probably never ever write and there's 94 95 00:07:17,530 --> 00:07:22,390 very few cases where this is actually useful which is the "no-preserve-root." 95 96 00:07:22,390 --> 00:07:31,180 And what that means is that along with everything else inside this command, it basically wipes your hard 96 97 00:07:31,180 --> 00:07:34,350 disk to the point where you cannot recover it. 97 98 00:07:34,390 --> 00:07:37,060 This guy said, "Monday morning mistake." 98 99 00:07:37,210 --> 00:07:43,420 "I basically just wiped my entire server," which obviously contains data from other people who are using 99 100 00:07:43,420 --> 00:07:44,100 his server. 100 101 00:07:44,200 --> 00:07:45,160 "And what do I do?" 101 102 00:07:45,160 --> 00:07:52,150 So as it turns out, this is actually a hoax where this guy is trying to advertise his server company. 102 103 00:07:52,360 --> 00:07:55,200 And I mean it's clever or is it not clever? 103 104 00:07:55,210 --> 00:08:01,630 I'm not sure that it's positive PR, but it got a lot of attention on the internets. 104 105 00:08:01,660 --> 00:08:06,170 So if you're interested, you can have a read of this and a link to it in this lesson. 105 106 00:08:06,190 --> 00:08:12,070 But basically, if you have a look at the answers, you can see that this is something really bad to never 106 107 00:08:12,070 --> 00:08:15,090 do. So with great power comes great responsibility. 107 108 00:08:15,130 --> 00:08:19,810 And in this module, I've introduced you to some of the most common commands that you're going to be finding 108 109 00:08:19,810 --> 00:08:20,940 yourself using, 109 110 00:08:21,040 --> 00:08:27,880 and also some of the most common shortcuts. In the last lesson, I posted a link to a cheat sheet of some 110 111 00:08:27,940 --> 00:08:29,790 other shortcuts that you can have a look at. 111 112 00:08:30,070 --> 00:08:35,430 And if you want to learn more about the command line, then this is a website that I highly recommend. 112 113 00:08:35,590 --> 00:08:36,630 I have nothing to do with them. 113 114 00:08:36,640 --> 00:08:39,400 It's just something that I found to be written quite well. 114 115 00:08:39,430 --> 00:08:45,950 So it's completely free and it's called the Command Line Tutorial, Learn Enough Command Line to Be Dangerous. 115 116 00:08:46,000 --> 00:08:53,060 Again, the title is repeating what we just said before, but it goes into more depth like a grepping kerl, 116 117 00:08:53,110 --> 00:08:58,060 all those things that you might have come across, and you will certainly come across more of it in your 117 118 00:08:58,060 --> 00:09:00,120 journey as a developer. 118 119 00:09:00,340 --> 00:09:02,390 So have a look at that if you're interested. 119 120 00:09:02,480 --> 00:09:07,740 And just before we head off, I want to show you something quite cool. Let's call it a bonus. 120 121 00:09:07,810 --> 00:09:18,280 And if you go into a Terminal and you type emacs -batch -l, and it's dunnet with two "Ns," 121 122 00:09:18,790 --> 00:09:20,220 and hit enter, 122 123 00:09:20,260 --> 00:09:28,900 you will get taken into a text-based to your own adventure game that dates back a long time, and it's 123 124 00:09:28,960 --> 00:09:34,520 included in emacs which is a text editor that comes bundled with all macOS. 124 125 00:09:34,570 --> 00:09:40,390 So you might have heard of Vim and Emacs, a highly divisive issue, and it's a really cool game that you can 125 126 00:09:40,390 --> 00:09:41,620 play within Terminal. 126 127 00:09:41,650 --> 00:09:47,560 And I myself have probably spent more than, you know, a good few hours on this before. 127 128 00:09:47,560 --> 00:09:49,380 So, again, play at your own peril. 128 129 00:09:49,390 --> 00:09:54,310 So it tells you a bit of a story and you can write text commands to play the game. 129 130 00:09:54,310 --> 00:09:58,480 So, for example, at this point, you're at a dead end of a dirt road and you find a shovel. 130 131 00:09:58,480 --> 00:10:03,470 So let's say something like, "Use a shovel." 131 132 00:10:03,580 --> 00:10:04,560 "I don't understand that." 132 133 00:10:04,570 --> 00:10:05,770 Okay, let's try something else. 133 134 00:10:05,800 --> 00:10:08,650 What about "pick up the shovel"? 134 135 00:10:08,740 --> 00:10:09,690 "I don't understand that." 135 136 00:10:09,730 --> 00:10:12,990 What about "take shovel"? 136 137 00:10:13,030 --> 00:10:13,750 Okay, great. 137 138 00:10:13,810 --> 00:10:16,180 So it recognizes that. "Taken." 138 139 00:10:16,420 --> 00:10:21,910 And what can we do with the shovel? Let's try "dig." "Digging here reveals nothing." 139 140 00:10:22,180 --> 00:10:24,560 And this is my personal favorite. 140 141 00:10:24,670 --> 00:10:29,800 What if let's just "eat shovel"? 141 142 00:10:30,700 --> 00:10:37,810 So as you can see, there's some pretty interesting end points. And have a play with it if you're interested, 142 143 00:10:37,870 --> 00:10:40,660 but otherwise, I will see you on the next module.