0
1
00:00:00,840 --> 00:00:01,070
All right.
1

2
00:00:01,080 --> 00:00:06,450
So in this lesson I want to introduce you to directory creation,
2

3
00:00:06,450 --> 00:00:12,060
file creation and directory manipulation. And we're going to be doing all of this inside the command line,
3

4
00:00:12,210 --> 00:00:13,470
just with our keyboards.
4

5
00:00:13,470 --> 00:00:21,690
So again right now I'm starting in my root directory over here and I am going to create a new folder
5

6
00:00:22,020 --> 00:00:22,950
right here.
6

7
00:00:23,130 --> 00:00:30,570
So obviously I can go through the right click, New Folder, all of that, but we are pro developers now,
7

8
00:00:30,600 --> 00:00:37,410
so we're going to get used to using the command line. So the command is mkdir or make directory, and
8

9
00:00:37,470 --> 00:00:39,560
then we're going to give our directory a name,
9

10
00:00:39,570 --> 00:00:42,720
so let's just call it Angela, right?
10

11
00:00:42,850 --> 00:00:47,520
You can see, there you go, pops up a new folder called Angela.
11

12
00:00:47,580 --> 00:00:58,600
Now let's cd into this new directory, and you can see that if I click on here, or if I use ls,
12

13
00:00:58,750 --> 00:01:00,560
that there's absolutely nothing in there.
13

14
00:01:00,570 --> 00:01:03,090
It's a empty folder.
14

15
00:01:03,090 --> 00:01:05,540
So what if I wanted to create a file?
15

16
00:01:05,730 --> 00:01:13,650
So in our graphical user interface I could, say, open up an application, like TextEdit, and I could make
16

17
00:01:13,650 --> 00:01:19,860
a file and write something in it and then save it inside my new directory.
17

18
00:01:19,890 --> 00:01:24,080
So I would have to do a little bit of navigating in order to get there,
18

19
00:01:24,090 --> 00:01:28,830
and then I have to give my file a name, let's call it Text and hit save.
19

20
00:01:28,830 --> 00:01:36,600
So now we have to exit the application and after all of that work I've got a text file and if we do
20

21
00:01:36,700 --> 00:01:36,990
ls
21

22
00:01:36,990 --> 00:01:43,440
now, you can see that text.rtf exists. But if you want to do the same thing using the command line
22

23
00:01:43,500 --> 00:01:48,460
then it's as simple as simply typing touch to create a new file.
23

24
00:01:48,660 --> 00:01:53,630
Then we're going to specify the name of the file, let's call it Text2, and then we give it an extension,
24

25
00:01:53,640 --> 00:02:00,780
.txt. And you can open it either by double clicking on it, which is what we're used to, or you can
25

26
00:02:00,780 --> 00:02:11,010
simply write open Text2, and it will open it using the default application, which is TextEdit in a
26

27
00:02:11,010 --> 00:02:19,020
Mac. Now you can specify which application you want to open this file in, and all you have to do is say
27

28
00:02:19,050 --> 00:02:25,800
the open, and you're going to use a -a flag, then you're going to specify the application that you
28

29
00:02:25,800 --> 00:02:26,510
want to use.
29

30
00:02:26,520 --> 00:02:34,340
So let's say that we want to open it inside Atom. So I can write Atom, and then I can specify that the
30

31
00:02:34,350 --> 00:02:41,580
file that I want to open, so Text2.txt, and hit enter, and it will open up the Atom application
31

32
00:02:41,580 --> 00:02:45,150
that I've got and then open up my file for me to be able to edit.
32

33
00:02:45,300 --> 00:02:52,560
So what if you wanted to delete files inside the command line? So currently I'm inside the Angela folder
33

34
00:02:52,800 --> 00:02:58,240
and there are two files, and I want to delete my Text.rtf.
34

35
00:02:58,440 --> 00:03:04,320
So then all you need to do is just use the rm command, which removes files
35

36
00:03:04,680 --> 00:03:13,110
if you type the command as is, so just rm, and then we're going to specify Text.rtf to remove,
36

37
00:03:13,230 --> 00:03:16,150
and once I hit enter you'll see it disappear
37

38
00:03:16,230 --> 00:03:17,820
also in the Finder as well.
38

39
00:03:18,150 --> 00:03:21,540
Now what if I want to remove all the files inside a folder?
39

40
00:03:21,750 --> 00:03:34,850
So let's create some more text files. So let's call it Text.txt, and then let's create
40

41
00:03:34,890 --> 00:03:35,520
Text3.txt.
41

42
00:03:35,520 --> 00:03:39,330
So now I've got Text, Text2, Text3.
42

43
00:03:39,380 --> 00:03:40,590
Little bit of a tongue twister there.
43

44
00:03:41,530 --> 00:03:43,700
And I want to remove all of them.
44

45
00:03:43,740 --> 00:03:48,960
So to do that you have to be inside the directory that you want to remove all the files from, and if
45

46
00:03:48,960 --> 00:03:51,750
you want to know which directory you're currently in,
46

47
00:03:51,750 --> 00:03:55,440
you can either look at the part that's before your user name and prompt,
47

48
00:03:55,470 --> 00:04:02,610
so in this case I'm inside a folder called Angela on Angela's MacBook Pro, but you can also use the 
48

49
00:04:02,610 --> 00:04:09,120
pwd, or print working directory command, and then when you hit enter it tells you your entire path and
49

50
00:04:09,120 --> 00:04:16,770
your current folder location. And now I want to remove all of them in one go without having to type remove
50

51
00:04:16,800 --> 00:04:18,580
Text.txt, etc..
51

52
00:04:18,690 --> 00:04:25,200
So again we're using the remove command and then we're simply going to use the * as a wildcard
52

53
00:04:25,530 --> 00:04:28,950
which matches everything that has every single name.
53

54
00:04:28,980 --> 00:04:35,190
And now if I hit enter you can see that all my three files inside my current directory are removed.
54

55
00:04:35,490 --> 00:04:40,170
So do you remember in the beginning of this module we mentioned that using the command line gives you
55

56
00:04:40,170 --> 00:04:42,390
more power, more control?
56

57
00:04:42,390 --> 00:04:49,350
And, as we all know, with great power comes great responsibility, and that means that you have to be careful
57

58
00:04:49,590 --> 00:04:56,070
when using certain commands because the graphical user interface isn't there to protect you.
58

59
00:04:56,070 --> 00:05:03,030
So for example if you were not inside the directory that you wanted to delete, say if you were inside
59

60
00:05:03,120 --> 00:05:10,710
your root directory and you, you know, tried to remove all the files inside your root directory, then it's
60

61
00:05:10,710 --> 00:05:12,910
probably not such a great idea.
61

62
00:05:12,930 --> 00:05:19,590
So always check which location you're in before you're doing some of these destructive commands.
62

63
00:05:19,590 --> 00:05:23,970
Now if you're inside your root directory and you tried to do remove *,
63

64
00:05:23,970 --> 00:05:29,550
nothing bad is actually going to happen, because there aren't any files that are inside this directory.
64

65
00:05:29,550 --> 00:05:35,680
There's only folders and to remove folders or remove directories there's a different command.
65

66
00:05:35,700 --> 00:05:42,500
So now I want to remove this Angela folder that I've created and I'm inside the right place to do it.
66

67
00:05:42,510 --> 00:05:46,100
I'm inside my root directory which is at this level.
67

68
00:05:46,230 --> 00:05:50,640
And again always check where you are by using the ls command.
68

69
00:05:50,640 --> 00:05:52,890
You can see that I am at this level.
69

70
00:05:52,890 --> 00:06:01,240
So now I want to remove this Angela directory and if I just simply write remove Angela and I hit enter,
70

71
00:06:01,260 --> 00:06:04,240
you can see it says that Angela is a directory.
71

72
00:06:04,290 --> 00:06:08,140
So this remove command by itself is not going to work.
72

73
00:06:08,160 --> 00:06:13,170
So to do it we actually have to add a flag which is the -r flag.
73

74
00:06:13,440 --> 00:06:16,530
So this allows you to remove a directory.
74

75
00:06:16,530 --> 00:06:22,140
So now let's try that again remove -r, and then we're going to use the Angela directory, and if
75

76
00:06:22,140 --> 00:06:28,710
we watch over here and I hit enter you can see that that directory is now gone, including all the files
76

77
00:06:28,710 --> 00:06:36,450
that it held, all the folders that are inside the Angela folder, and it removes all of its child components.
77

78
00:06:36,450 --> 00:06:39,510
So again these are destructive commands.
78

79
00:06:39,510 --> 00:06:41,640
Be really careful when you're using them.
79

80
00:06:41,640 --> 00:06:49,950
And in fact there's a pretty hilarious bit of Internet history which is where somebody submitted a question
80

81
00:06:50,280 --> 00:06:54,210
to Stack Exchange Server Fault, which is similar to Stack Overflow,
81

82
00:06:54,240 --> 00:06:56,960
but it's more for sysadmin and network admins.
82

83
00:06:56,970 --> 00:07:00,580
So what he said was Monday morning mistake.
83

84
00:07:00,990 --> 00:07:07,350
He used the sudo command, which stands for super user do, which uses your admin privileges to basically
84

85
00:07:07,350 --> 00:07:13,950
allow you to do things are probably a little bit dangerous, and he used the remove command, and then the 
85

86
00:07:14,040 --> 00:07:14,880
-rf flag.
86

87
00:07:14,880 --> 00:07:20,340
So we've already seen the -r, which allows you to remove entire directories and all the folders
87

88
00:07:20,520 --> 00:07:22,970
and all the child folders it contains.
88

89
00:07:22,980 --> 00:07:26,250
He also used the f flag which stands for force,
89

90
00:07:26,280 --> 00:07:28,650
so this doesn't ask you for a confirmation.
90

91
00:07:28,830 --> 00:07:34,290
And then the very last thing which is something that you should probably never ever write and there's
91

92
00:07:34,290 --> 00:07:39,150
very few cases where this is actually useful which is the no-preserve-root.
92

93
00:07:39,150 --> 00:07:47,970
And what that means is that, along with everything else inside this command, it basically wipes your hard
93

94
00:07:47,970 --> 00:07:51,120
disk to the point where you cannot recover it.
94

95
00:07:51,180 --> 00:07:53,900
This guy said Monday morning mistake,
95

96
00:07:54,000 --> 00:08:00,180
I basically just wiped my entire server, which obviously contains data from other people who are using
96

97
00:08:00,180 --> 00:08:00,920
his server.
97

98
00:08:01,030 --> 00:08:01,950
And what do I do?
98

99
00:08:01,950 --> 00:08:08,960
So as it turns out this is actually a hoax where this guy is trying to advertise his server company.
99

100
00:08:09,120 --> 00:08:12,000
And I mean it's clever or is it not clever.
100

101
00:08:12,000 --> 00:08:18,440
I'm not sure that it's positive PR but it got a lot of attention on the internets.
101

102
00:08:18,450 --> 00:08:22,980
So if you're interested you can have a read of this, and I’ll link to it in this lesson,
102

103
00:08:22,980 --> 00:08:28,830
but basically if you have a look at the answers, you can see that this is something really bad to never
103

104
00:08:28,830 --> 00:08:29,150
do.
104

105
00:08:29,220 --> 00:08:31,830
So with great power comes great responsibility.
105

106
00:08:31,890 --> 00:08:36,600
And in this module I've introduced you to some of the most common commands that you're going to be finding
106

107
00:08:36,600 --> 00:08:40,020
yourself using and also some of the most common shortcuts.
107

108
00:08:40,170 --> 00:08:45,720
And if you want to learn more about the command line then this is a web site that I highly recommend.
108

109
00:08:45,720 --> 00:08:49,550
I have nothing to do with them, it’s just something that I found to be written quite well.
109

110
00:08:49,560 --> 00:08:51,630
So it's completely free,
110

111
00:08:51,630 --> 00:08:56,130
and it's called the Command Line Tutorial, Learn Enough Command Line to Be Dangerous.
111

112
00:08:56,130 --> 00:09:03,210
Again the title is repeating what we just said before, but it goes into more depth like grepping, curl,
112

113
00:09:03,240 --> 00:09:07,950
all of those things that you might have come across and you will certainly come across more of it in
113

114
00:09:07,950 --> 00:09:09,570
your journey as a developer.
