1 00:00:01,780 --> 00:00:07,230 A big part of being a developer is being able to use the terminal or the command line. 2 00:00:07,640 --> 00:00:13,480 Well, what is it? In this video we're going to tackle this question and teach you a couple of very useful 3 00:00:13,480 --> 00:00:14,520 commands. 4 00:00:14,710 --> 00:00:18,860 Now on a Mac you simply do command space (CMD-Space) and type in 'Terminal'. 5 00:00:19,060 --> 00:00:21,520 Press 'Enter' and then the terminal will open for you. 6 00:00:21,520 --> 00:00:24,610 It's one of your applications and it's on every computer. 7 00:00:24,610 --> 00:00:30,820 If you're on a Windows machine then it is the command prompt and I'll leave instructions at the end 8 00:00:30,820 --> 00:00:36,880 of this video of how you can access them but you might remember this from the Traceroutes video earlier on 9 00:00:37,240 --> 00:00:38,190 in the course. 10 00:00:38,710 --> 00:00:47,130 But what is it? Well, it's how humans originally communicated with computers up until the 1980s. 11 00:00:47,450 --> 00:00:53,830 It was the main way humans gave instructions to computers and computers gave output to the humans. 12 00:00:54,020 --> 00:01:00,350 We didn't have something called the GUI or the Graphical User Interface such as me opening up a new 13 00:01:00,350 --> 00:01:05,930 folder and changing the name of this folder or opening up Google Chrome. 14 00:01:05,930 --> 00:01:09,400 I don't really need to know how this is done behind the scenes. 15 00:01:09,530 --> 00:01:13,760 I just click on an icon and it opens it up magically for me. 16 00:01:13,760 --> 00:01:19,970 But command lines are really useful because you can do the exact same thing that you do visually on 17 00:01:19,970 --> 00:01:26,570 a Graphical User Interface like I have here on the command line but they tend to be much much faster 18 00:01:26,570 --> 00:01:28,670 to do as I'm going to show you in this video. 19 00:01:28,670 --> 00:01:34,280 And there are also common ways to access different computers around the world, like if you need to access 20 00:01:34,280 --> 00:01:37,650 a server in another country where your web app is hosted. 21 00:01:37,820 --> 00:01:41,960 Well you'd use the command line and I'll show you how to do that later on in the course. 22 00:01:43,250 --> 00:01:48,710 Now in your day to day job you'll be using the terminal a lot because you'll have to access servers 23 00:01:49,110 --> 00:01:51,850 the database your front-end application. 24 00:01:52,010 --> 00:01:54,800 But you can do all of that in one from the terminal. 25 00:01:54,860 --> 00:02:00,320 You can also download scripts that other people have written from the internet so you can use in your 26 00:02:00,320 --> 00:02:01,410 project. 27 00:02:01,580 --> 00:02:05,290 Now these are all things I'm going to show you in the later sections. 28 00:02:05,570 --> 00:02:10,539 The commands that I'm about to show you work on a Mac or Linux. For Windows, 29 00:02:10,550 --> 00:02:15,090 I'll have the Windows version command at the bottom of the video as we progress, 30 00:02:15,110 --> 00:02:18,220 most of them are the same but there are a few differences. 31 00:02:18,260 --> 00:02:20,590 So let's get started. 32 00:02:20,960 --> 00:02:24,040 The first command I'm going to show you is the 'ls' command. 33 00:02:24,310 --> 00:02:32,270 I simply type in and press enter and it lists everything that is in my current directory. 34 00:02:32,270 --> 00:02:33,270 What is my current directory? 35 00:02:33,470 --> 00:02:42,610 Well, I do 'pwd' for Present Working Directory and I see that I'm in the '/Users/' , that's my user name, 36 00:02:42,620 --> 00:02:47,260 so I'm in my username folder and these are all the things available to me. 37 00:02:47,720 --> 00:02:53,790 If I do 'cd' then I can go into this. If I wanted to go to, let's say, desktop, 38 00:02:53,810 --> 00:02:57,030 I do 'cd Desktop'. 39 00:02:57,350 --> 00:03:03,800 And now if I do 'ls', I see that I have 'untitled folder', because that's the only thing on my desktop right 40 00:03:03,800 --> 00:03:05,490 now. 41 00:03:05,630 --> 00:03:08,440 I can also do 'cd ..' 42 00:03:08,840 --> 00:03:15,500 and this brings me back to one directory up. 43 00:03:15,570 --> 00:03:26,110 I can also do 'clear' to clear up my terminal and have a nice fresh slate. There's a short command 'cd /' 44 00:03:26,240 --> 00:03:28,780 and this takes me to the root directory. 45 00:03:28,850 --> 00:03:33,650 If I do 'ls', I see that I have 'Applications, Library, System, Users..' 46 00:03:33,680 --> 00:03:40,220 That's the root directory of my Mac, essentially my Macintosh HD. 47 00:03:40,240 --> 00:03:49,800 I can also do 'cd ~' and this takes me to the user directory. 48 00:03:50,340 --> 00:03:51,830 Let's clear this again. 49 00:03:52,210 --> 00:03:54,390 And if we check where we are. 50 00:03:54,430 --> 00:04:00,270 All right, let's change this 'untitled folder' to something like 'test', okay? 51 00:04:00,360 --> 00:04:05,490 Let's say I'm in the user directory right now, I want to access 'Desktop' and then the 'test' folder. 52 00:04:05,550 --> 00:04:16,140 I would simply do 'cd Desktop/' and then 'test'. And now I'm in the 'test' folder, but there's nothing 53 00:04:16,140 --> 00:04:16,820 in there. 54 00:04:17,190 --> 00:04:26,330 So one thing we can do is I can say 'open .' and it opens a folder that we're currently in. Okay, we're 55 00:04:26,330 --> 00:04:27,480 in the 'test' folder. 56 00:04:27,620 --> 00:04:36,910 Now if I just put this to the side over here so you can see, I can say 'mkdir(make directory)', which is make a 57 00:04:36,910 --> 00:04:44,950 folder 'name'. So 'name' here will be whatever I want the folder to be titled. Let's just say this folder 58 00:04:44,950 --> 00:04:45,760 would be called 'webapp'. 59 00:04:48,900 --> 00:04:50,130 Did you see that? 60 00:04:50,280 --> 00:04:56,440 Now 'webapp' shows up in my folder. Let's change the view here so you can see it better. 61 00:04:56,440 --> 00:04:57,490 There you go. 62 00:04:57,550 --> 00:05:05,860 If I do 'ls' now, I see that we have the 'webapp' folder and as we know, we can go into it. Let's double 63 00:05:05,860 --> 00:05:07,030 click here to see what we have. 64 00:05:07,030 --> 00:05:10,580 We have absolutely nothing. 65 00:05:10,790 --> 00:05:16,040 Well, We can create a file in here by saying 'touch' and the name of the file. 66 00:05:16,040 --> 00:05:19,890 So let's just do 'index.html'. 67 00:05:19,910 --> 00:05:20,480 There you go, 68 00:05:20,750 --> 00:05:22,470 'index.html' 69 00:05:22,520 --> 00:05:30,320 Now what if we wanted to open this 'index.html' again, we just do 'open' and the '.(dot)' means we open 70 00:05:30,440 --> 00:05:32,980 the folder we're currently in which is here. 71 00:05:33,140 --> 00:05:39,710 But if I do 'open index.html', it opens the file for us. 72 00:05:39,720 --> 00:05:40,540 How cool is that? 73 00:05:40,740 --> 00:05:43,890 But 'index.html' is pretty empty right now. 74 00:05:44,750 --> 00:05:51,300 Wouldn't it be nice if we could open Sublime Text from here and add something? Again, you can do that with 'open'. 75 00:05:51,970 --> 00:06:01,210 You put in 'a', so '-a' for application and the name of the application, so 'Sublime Text'. Close the double 76 00:06:01,210 --> 00:06:04,740 quotes, press enter, and look at that. 77 00:06:04,870 --> 00:06:09,380 I have Sublime Text. But if we wanted to do, 78 00:06:09,460 --> 00:06:19,780 '-a(application) Sublime Text' and open the 'index.html' file. We just do this. 79 00:06:19,950 --> 00:06:26,300 And now I can say 'html', and it will just say 'Helloooo world!' 80 00:06:27,620 --> 00:06:28,580 Save that. 81 00:06:29,000 --> 00:06:31,840 And if I do 'open index.html', 82 00:06:33,340 --> 00:06:36,700 We have our 'index.html' file loaded. 83 00:06:36,740 --> 00:06:43,380 Wasn't that a lot faster than right clicking, creating a folder, then dragging everything to Sublime Text. 84 00:06:43,420 --> 00:06:47,030 And as you can see, you can do things really really faster. 85 00:06:47,130 --> 00:06:48,230 OK, let's change something. 86 00:06:48,340 --> 00:06:55,360 Let's - I'm going to close Google Chrome and Sublime, and in the 'webapp', let's say I wanted to change the name 87 00:06:55,360 --> 00:06:58,530 of 'index.html' to 'about.html'. 88 00:06:58,670 --> 00:07:02,640 Well, I'll do the 'mv' command, which stands for 'move', 89 00:07:02,770 --> 00:07:08,350 but it just moves 'the index.html' file to 'about.html'. 90 00:07:08,710 --> 00:07:09,790 So it's a little trick - 91 00:07:09,790 --> 00:07:17,380 You're essentially just moving one file to another but, by changing the name, you create a new file and 92 00:07:17,380 --> 00:07:20,170 you replace it with the old one. 93 00:07:20,200 --> 00:07:24,340 So now I have 'about.html'. 94 00:07:24,540 --> 00:07:25,620 Very cool. 95 00:07:25,750 --> 00:07:28,300 Now these commands typing them can get pretty tiring. 96 00:07:28,300 --> 00:07:35,590 I can press the up arrow and it goes through my entire history, which is very cool. I can also press the tab 97 00:07:35,590 --> 00:07:43,410 key and it will bring up my most recent commands or completes what I'm about to write so you can do it 98 00:07:43,920 --> 00:07:44,990 really really fast. 99 00:07:45,060 --> 00:07:48,470 And when your commands get longer and longer it's a very useful thing to do. 100 00:07:49,590 --> 00:07:50,010 OK. 101 00:07:50,190 --> 00:07:53,460 I don't really need the 'about.html' file anymore. 102 00:07:53,490 --> 00:07:54,810 Let's remove it. 103 00:07:54,810 --> 00:08:04,340 We do 'rm', for 'remove', and the name of the file 'about.html'. 104 00:08:04,540 --> 00:08:05,800 It's been removed. 105 00:08:05,800 --> 00:08:06,610 Perfect. 106 00:08:06,640 --> 00:08:11,890 Now, what about the 'webapp' file, we can remove that as well. 107 00:08:11,900 --> 00:08:14,660 But if I just do 'rm webapp', 108 00:08:18,030 --> 00:08:19,260 well, it's not going to work. 109 00:08:19,260 --> 00:08:26,300 First of all if I do 'ls' or 'pwd(present working directory)', I'm in the 'webapp' folder. 110 00:08:26,370 --> 00:08:29,800 So I need to move back to the 'test' folder. 111 00:08:29,820 --> 00:08:31,300 Let's clear here. 112 00:08:31,500 --> 00:08:34,039 Do 'cd'. 113 00:08:34,049 --> 00:08:44,070 Now, my 'pwd(present working directory)' is - I'm in the 'test' - so I can remove 'webapp' by doing 'rm webapp'. 114 00:08:44,250 --> 00:08:47,930 But 'rm' only works for files. To remove a directory or folder, 115 00:08:48,120 --> 00:08:52,850 You need to do 'rm' and then use the '-r' option 116 00:08:53,940 --> 00:08:57,160 and then the folder name, in our case's the 'webapp'. 117 00:08:57,460 --> 00:08:59,270 There you go, it's gone. 118 00:08:59,470 --> 00:09:03,220 And with that, you know what, we can remove the 'test' folder as well. 119 00:09:03,220 --> 00:09:10,720 We can go back to our 'Desktop' and then do 'rm -r test'. 120 00:09:11,010 --> 00:09:12,340 There you go, it's gone. 121 00:09:13,690 --> 00:09:15,570 And one last trick on a Mac. 122 00:09:15,580 --> 00:09:16,240 You can do this. 123 00:09:21,530 --> 00:09:24,280 Right? 124 00:09:24,380 --> 00:09:26,720 Very very cool. 125 00:09:26,850 --> 00:09:32,520 As you can see, you can have a lot of power with the terminal. And I want you to get used to writing commands 126 00:09:32,520 --> 00:09:36,730 on here. And from now on, try creating files and folders this way. 127 00:09:36,840 --> 00:09:42,330 Eventually you'll get more and more comfortable with it and things will be much faster than 128 00:09:42,540 --> 00:09:46,770 just using the GUI. In the developer environment section, 129 00:09:46,770 --> 00:09:53,480 I'll show you how you can change this boring black and white terminal to something like this. 130 00:09:57,770 --> 00:09:58,760 That's it for now. 131 00:10:02,130 --> 00:10:03,850 See you in the next video. 132 00:10:04,350 --> 00:10:04,910 Bye-bye