1 00:00:00,270 --> 00:00:00,870 All right. 2 00:00:00,870 --> 00:00:06,090 So now that you know how to make files and directories using the touch and mkdir air commands, let's 3 00:00:06,090 --> 00:00:08,490 take it up a notch and mess around a bit. 4 00:00:08,490 --> 00:00:14,130 So let's say that you're working on a big five year project and every month because the admin staff 5 00:00:14,130 --> 00:00:20,220 hate you, you need to write 100 memo files to keep track of the project and the folder should be named 6 00:00:20,220 --> 00:00:28,110 something like Jan 2017 Feb 2017 Mar 20 Mar 2017 and so on and so on for five years. 7 00:00:28,110 --> 00:00:36,180 And in each of these folders there should be 100 files, far one file two fall three all the way until 8 00:00:36,180 --> 00:00:37,380 file 100. 9 00:00:37,560 --> 00:00:41,910 How can you create those files and folders up front? 10 00:00:42,690 --> 00:00:45,780 Well, doing it graphically would be horrific. 11 00:00:45,780 --> 00:00:47,850 There's actually just no way around it. 12 00:00:47,850 --> 00:00:51,720 There will be a whole lot of copying and pasting and a whole lot of renaming. 13 00:00:51,720 --> 00:00:56,670 And you're right click finger would be basically in agony by the end of the whole ordeal. 14 00:00:56,670 --> 00:01:00,210 But let me show you how easy it is to do on the command line. 15 00:01:00,210 --> 00:01:06,270 So to make this possible, we're going to use a powerful feature of the shell known as brace expansion. 16 00:01:06,270 --> 00:01:07,590 And this is totally awesome. 17 00:01:07,920 --> 00:01:08,850 Check this out. 18 00:01:09,150 --> 00:01:13,620 So let's go ahead and open our terminal using our control alternate keyboard shortcut. 19 00:01:13,620 --> 00:01:18,420 And then what we're going to do is we're going to head over to the desktop using our command, and we're 20 00:01:18,420 --> 00:01:22,500 going to make a big folder called Project and there we are. 21 00:01:22,500 --> 00:01:25,410 It has appeared now in here. 22 00:01:25,740 --> 00:01:28,500 This is let's go change into it, change into that project folder. 23 00:01:28,500 --> 00:01:33,510 We can see that now we're in the project folder on the desktop and this is where the magic happens. 24 00:01:33,930 --> 00:01:36,390 We need to make 60 folders, right? 25 00:01:36,390 --> 00:01:37,830 And they should all be in the format. 26 00:01:37,830 --> 00:01:42,300 Jan 2017 Feb 2017 Mar 2017. 27 00:01:42,300 --> 00:01:50,940 Okay, so like three three letters then 2017 all the way up until December 20, 22, so Dec 2022, which 28 00:01:50,940 --> 00:01:52,260 is when the project ends. 29 00:01:52,380 --> 00:01:56,670 So what if I told you we could make all of those folders in one line? 30 00:01:57,450 --> 00:02:01,470 This is all possible using the power of brace expansion. 31 00:02:01,470 --> 00:02:02,670 So here comes the command. 32 00:02:02,850 --> 00:02:06,180 And what I'm going to do is I'm actually going to maximize the screen because it's kind of a big one. 33 00:02:06,270 --> 00:02:11,370 What we're going to do is we're going to type mkdir, then we're going to open up a pair of braces and 34 00:02:11,370 --> 00:02:16,020 the braces are these squiggly brackets here and then we're going to type without any spaces. 35 00:02:16,020 --> 00:02:27,300 Jan Comma, February, comma, March, comma, April, May, June, July, August, September, October, 36 00:02:27,300 --> 00:02:30,360 November, December without any spaces at all. 37 00:02:30,360 --> 00:02:32,700 Okay, then I'm going to type in underscore. 38 00:02:32,730 --> 00:02:35,610 Then we're going to open up open up another pair of braces. 39 00:02:35,610 --> 00:02:46,980 Okay, then 2017, 2018, 20, 19, 20, 20, 20, 21 and 20, 22. 40 00:02:47,430 --> 00:02:48,030 Whew. 41 00:02:48,060 --> 00:02:49,740 So that's quite a long command, right? 42 00:02:49,740 --> 00:02:53,940 But what's happening here is something called brace expansion. 43 00:02:53,940 --> 00:03:00,600 And here we have some braces, so we've got one set here and another set here for the for the years. 44 00:03:00,600 --> 00:03:06,120 And the way that the shell is going to expand these braces is similar to how you would expand brackets 45 00:03:06,120 --> 00:03:07,290 in algebra class. 46 00:03:07,320 --> 00:03:07,770 Okay. 47 00:03:07,800 --> 00:03:17,670 So what happened first is you get January 2017, then February 2017, then March 2017 and so on and 48 00:03:17,670 --> 00:03:22,620 so on until you get December 2017, then it'll just start all over again. 49 00:03:22,620 --> 00:03:30,060 You'll get January 2018, February 2018, then March, April, May, June, July, all the way until 50 00:03:30,060 --> 00:03:39,060 you get December 2018 and so on and so on, until you get all the way until December 20, 22. 51 00:03:39,210 --> 00:03:41,550 Okay, so enough, enough suspense. 52 00:03:41,550 --> 00:03:43,020 Let's go ahead and press enter. 53 00:03:43,590 --> 00:03:44,700 Let's go ahead and run that. 54 00:03:44,700 --> 00:03:46,830 Now, let's see if it works. 55 00:03:46,830 --> 00:03:48,540 So we're going to go into our project folder. 56 00:03:49,990 --> 00:03:52,320 Oh, my goodness. 57 00:03:52,320 --> 00:03:53,550 Look how amazing that is. 58 00:03:53,550 --> 00:03:53,760 Right. 59 00:03:53,760 --> 00:04:00,870 So we've managed to create folders in that wonderful format there for every single one of the years. 60 00:04:00,870 --> 00:04:06,390 And if we highlight them, it tells us that the 72 folders are actually created. 61 00:04:06,390 --> 00:04:16,050 So from January 2017, right here, all the way until December 2022, which is right there and everything 62 00:04:16,050 --> 00:04:17,940 in between, isn't that awesome? 63 00:04:18,870 --> 00:04:23,910 Just just as an aside as well, if I just maximize this here to save us a bit of typing, we could have 64 00:04:23,910 --> 00:04:28,170 actually, instead of typing out each of the dates because it's just numbers. 65 00:04:28,170 --> 00:04:29,490 They're just numbers, right. 66 00:04:29,910 --> 00:04:31,890 That are in a, in a constant pattern. 67 00:04:31,890 --> 00:04:33,510 We could have just done dot dot. 68 00:04:33,510 --> 00:04:36,690 So 2017 to 2022. 69 00:04:36,720 --> 00:04:38,280 So that's another aside right there. 70 00:04:38,280 --> 00:04:41,850 Now imagine how long it would have taken to do that stuff. 71 00:04:41,850 --> 00:04:43,440 Using point and click methods. 72 00:04:43,440 --> 00:04:45,450 Can imagine how annoying that would have been. 73 00:04:45,510 --> 00:04:47,940 Well, we just did it in one command line. 74 00:04:49,710 --> 00:04:50,070 Okay. 75 00:04:50,100 --> 00:04:54,600 So now that we're sitting here feeling very smug that our command line has just created like a bajillion 76 00:04:54,600 --> 00:05:00,630 folders all in one go, we've still got a little bit to do, and that is we've got to create 100 files 77 00:05:00,630 --> 00:05:03,030 in each of these folders. 78 00:05:03,060 --> 00:05:04,620 Now, how are we going to do that? 79 00:05:04,650 --> 00:05:06,330 Well, actually, it's quite easy. 80 00:05:06,330 --> 00:05:08,010 We'll just use base expansion again. 81 00:05:08,010 --> 00:05:12,510 So what we're going to do is we're going to open up our terminal again, go onto the desktop, go into 82 00:05:12,510 --> 00:05:13,380 the project folder. 83 00:05:13,560 --> 00:05:13,860 Okay. 84 00:05:13,890 --> 00:05:17,130 Now in here, I'm actually going to maximize the screen. 85 00:05:17,130 --> 00:05:20,730 Watch what just watch what I do and then we'll see how it works. 86 00:05:20,800 --> 00:05:21,210 Okay. 87 00:05:21,840 --> 00:05:24,880 So we're going to type touch, then I'm going to open up the braces. 88 00:05:24,900 --> 00:05:35,250 Jan February, March, April, May, June, July, August, September, October, November, December. 89 00:05:35,280 --> 00:05:39,960 Our underscore and our our years. 90 00:05:39,960 --> 00:05:42,060 So 2017, 2022. 91 00:05:42,060 --> 00:05:49,050 Oh, by the way, it doesn't just have to be numbers, it could be A to Z or A to Z or something like 92 00:05:49,500 --> 00:05:51,840 B to F or something like that. 93 00:05:52,080 --> 00:05:57,390 So anything that is, that has a pattern like the alphabet or numbers, and you can use the dot dot 94 00:05:57,390 --> 00:05:58,440 thing to make that happen. 95 00:05:58,680 --> 00:06:07,450 But we're after 2017 till 2022 now inside each of those folders, we're now going to make a file call 96 00:06:07,530 --> 00:06:11,940 that starts with file, and then the number is 1 to 100. 97 00:06:13,410 --> 00:06:15,870 So what is going on here? 98 00:06:15,870 --> 00:06:16,620 This is mad. 99 00:06:16,620 --> 00:06:19,950 Ziad, where where has this command come from? 100 00:06:19,950 --> 00:06:26,130 Well, basically what I'm saying is for each of these folders from January 2017, all the way until 101 00:06:26,130 --> 00:06:29,820 December 2022, in each of those, make file 1 to 100. 102 00:06:30,240 --> 00:06:31,920 Now, this is just a bit of fun. 103 00:06:31,920 --> 00:06:34,920 Okay, so don't worry if it seems a bit like what? 104 00:06:35,430 --> 00:06:38,250 It's just to show you how powerful the shell can be. 105 00:06:38,250 --> 00:06:39,070 Let's take a look at it. 106 00:06:39,330 --> 00:06:43,020 So let's run that and let's close the terminal again. 107 00:06:43,020 --> 00:06:44,070 Let's go ahead and take a look. 108 00:06:44,070 --> 00:06:49,320 Let's open up June 2022, because that's that's a good date. 109 00:06:49,320 --> 00:06:51,570 So if we open up June 2022, we click that. 110 00:06:51,750 --> 00:06:55,320 Oh, my goodness, we've got file one, two, 100. 111 00:06:55,320 --> 00:06:56,640 Okay, maybe that was just a fluke. 112 00:06:56,640 --> 00:06:58,860 What if we open up December 2020? 113 00:06:58,950 --> 00:06:59,250 Nope. 114 00:06:59,250 --> 00:07:01,140 This file 1 to 100 in there as well. 115 00:07:01,140 --> 00:07:06,360 What if we open up January or let's say April 2020? 116 00:07:06,390 --> 00:07:07,170 There we go again. 117 00:07:07,170 --> 00:07:09,780 We've got far 1 to 100. 118 00:07:10,140 --> 00:07:12,150 So isn't that awesome? 119 00:07:12,150 --> 00:07:19,980 Guys like you can see the way that we've just used brace expansion to make our terminal command unbelievably 120 00:07:19,980 --> 00:07:20,520 powerful. 121 00:07:20,520 --> 00:07:24,870 And if we've got 72 folders, I said we were only going to do it for five years. 122 00:07:24,870 --> 00:07:26,220 We ended up doing it for six. 123 00:07:26,220 --> 00:07:33,150 But if we have now got a 72 folders with 100 files in it each, we've just used one command line to 124 00:07:33,150 --> 00:07:37,560 create about 7200 files in one go. 125 00:07:37,560 --> 00:07:43,800 Now, I hope you can see just how powerful the shell is from from that little example right there. 126 00:07:44,760 --> 00:07:50,400 And by the way, brace expansion isn't only possible for the touch and mkdir commands, by the way, 127 00:07:50,400 --> 00:07:53,100 it's actually usable across the whole shell. 128 00:07:53,100 --> 00:07:56,550 So, for example, let's take the LZ command, let's take the LZ command. 129 00:07:57,000 --> 00:08:00,480 We can look in every single folder and get a list of what's in there. 130 00:08:00,480 --> 00:08:08,520 So if I do Jan, February, March, April, May, June, July, August, September, October, November, 131 00:08:08,520 --> 00:08:13,680 December, and then 2017 till 2022. 132 00:08:14,700 --> 00:08:18,990 Okay, so I'm saying list out the contents of every single one of these folders basically. 133 00:08:18,990 --> 00:08:21,480 And I press enter, oops, I'm in the wrong place. 134 00:08:21,840 --> 00:08:28,350 So I'll go to desktop slash project now press up key twice to get back there. 135 00:08:28,380 --> 00:08:35,159 Go again where we now can see the contents of every single one of the folders and you can see they all 136 00:08:35,159 --> 00:08:37,500 have 100 files in it. 137 00:08:38,400 --> 00:08:43,830 And we can see here that we get the files 1 to 100 and every folder and it might look like the file 138 00:08:43,830 --> 00:08:45,420 ends in file 99. 139 00:08:45,420 --> 00:08:51,000 But what's actually happening is if you look over here near file, what it's doing is it's sorting them 140 00:08:51,240 --> 00:08:53,070 alphabetically or sorting them numerically here. 141 00:08:53,070 --> 00:08:58,020 So you see file one, file ten, file 100 because they all start with one, right? 142 00:08:58,020 --> 00:08:59,580 And then the nines end up over there. 143 00:08:59,580 --> 00:09:02,550 But no, we are getting files, 1 to 100 in each. 144 00:09:03,270 --> 00:09:06,970 And let's let's say that we wanted to take all of this output, right? 145 00:09:06,990 --> 00:09:12,470 This massive output that we just got and redirect it, redirect all that output into a file called output 146 00:09:12,480 --> 00:09:13,320 txt. 147 00:09:13,530 --> 00:09:20,940 And now when we, when we take a look, we've now got a file called txt and if when we take a look in 148 00:09:20,940 --> 00:09:25,410 there, we can see that we've got all of that content in there. 149 00:09:25,410 --> 00:09:31,140 So April 2017, it tells us the files that that has and then it tells us what's in April 2018 and it 150 00:09:31,140 --> 00:09:34,590 tells the files in there and this is all alphabetically sorted in there. 151 00:09:34,620 --> 00:09:35,700 Isn't that awesome? 152 00:09:36,210 --> 00:09:37,110 I'm just showing you here. 153 00:09:37,110 --> 00:09:44,580 We now have an epic file with the contents of 72 folders and in about 7200 files in just one command 154 00:09:44,580 --> 00:09:44,940 line. 155 00:09:44,940 --> 00:09:49,140 Tell me that isn't epic and would have took you forever to do using point and. 156 00:09:49,250 --> 00:09:54,650 Like methods now I appreciate this is really is this bit is really going to be a bit like whoa and that's 157 00:09:54,650 --> 00:09:55,370 okay all right. 158 00:09:55,370 --> 00:10:00,320 I'm just showing you these basic skills have these basic skills such as creating one file or creating 159 00:10:00,320 --> 00:10:06,140 one folder can easily be turbocharged with very little effort, as long as you understand a little bit 160 00:10:06,140 --> 00:10:08,360 about brace expansion and wildcards. 161 00:10:08,360 --> 00:10:13,070 But I'll leave the imagination as to why why you would do so up to you. 162 00:10:13,550 --> 00:10:15,860 Because these skills can be applied to many different things. 163 00:10:15,860 --> 00:10:19,790 And, you know, just just to just to show a much simpler case of brace expansion. 164 00:10:19,790 --> 00:10:26,390 If we go to the desktop right here and let's say we just want to instead of saying touch, file a, 165 00:10:26,630 --> 00:10:34,190 text, file B txt and file c txt which will work fine, we'll create three files and brace expansion 166 00:10:34,190 --> 00:10:38,300 just makes that a bit easier by saying file. 167 00:10:38,300 --> 00:10:42,530 You give it some brackets a, b, c, txt. 168 00:10:42,560 --> 00:10:47,180 So you can say we're using the the bracket, the braces here because it's going to go file a text file 169 00:10:47,210 --> 00:10:49,850 b txt file XD a press enter. 170 00:10:50,270 --> 00:10:52,790 Now we are we've used brace expansion to expand that out. 171 00:10:53,180 --> 00:10:56,480 So brace expansion comes into play all over the place. 172 00:10:56,480 --> 00:11:01,220 And because here we are, we've got some text which is a follows a very simple pattern. 173 00:11:01,220 --> 00:11:04,850 We can use the dot dot here and we're going to get the same result. 174 00:11:05,180 --> 00:11:10,610 We could we could maybe say, okay, I want file F all the way to V. 175 00:11:11,240 --> 00:11:17,540 Now we are going to get file V all the way to F on the desktop as well. 176 00:11:17,540 --> 00:11:19,460 So here we are here as F and there's V. 177 00:11:19,460 --> 00:11:21,350 So just showing you that's brace expansion. 178 00:11:21,350 --> 00:11:23,000 It's not particularly complicated thing. 179 00:11:23,240 --> 00:11:28,520 Trust me, there are useful things for what I'm showing you here, but I just wanted to show you just 180 00:11:28,520 --> 00:11:31,670 how powerful the shell can be with just a little bit of tweaking. 181 00:11:32,420 --> 00:11:34,790 So that's enough of command line craziness for now. 182 00:11:35,000 --> 00:11:39,560 Let's just have a quick recap of what was actually important from the last two videos. 183 00:11:39,560 --> 00:11:44,120 So first of all, you saw how to use the touch command to create new files and the use also saw how 184 00:11:44,120 --> 00:11:50,000 to use the mkdir command to create new directories, which is my favorite way of saying the command 185 00:11:50,000 --> 00:11:50,600 by the way. 186 00:11:50,600 --> 00:11:56,630 And you also saw that the mkdir command also has a powerful p option that can be used to create entire 187 00:11:56,630 --> 00:11:57,410 folder paths. 188 00:11:57,410 --> 00:12:02,630 So this is creating one folder inside of another folder inside of another folder, all from scratch, 189 00:12:02,630 --> 00:12:04,400 which is very, very powerful stuff. 190 00:12:04,610 --> 00:12:10,760 You learn that creating folder files and folders in Linux is case sensitive, and you learn that it's 191 00:12:10,760 --> 00:12:13,370 kind of a bad idea to have spaces in your file names. 192 00:12:13,370 --> 00:12:15,620 So use underscores instead. 193 00:12:15,620 --> 00:12:21,200 And finally we took file and folder creation to the next level by using brace expansion and embrace. 194 00:12:21,200 --> 00:12:23,000 Expansion is kind of an advanced technique. 195 00:12:23,000 --> 00:12:27,290 So don't worry if you didn't understand it, it's not technically part of the course, but you got to 196 00:12:27,290 --> 00:12:28,400 see it here anyway. 197 00:12:28,400 --> 00:12:29,480 So lucky you. 198 00:12:29,570 --> 00:12:34,730 But now that we've got a whole bunch of files and folders cluttering up our computer in the next video, 199 00:12:34,730 --> 00:12:36,530 you're going to learn how to remove them. 200 00:12:36,530 --> 00:12:41,360 So to learn how to delete files and folders, I'll see you in the next video.