1 00:00:00,180 --> 00:00:01,740 Hello the beautiful people. 2 00:00:01,740 --> 00:00:06,780 And welcome to this video where we're going to be kickstarting our discussion of how to delete files 3 00:00:06,780 --> 00:00:09,180 and directories using the command line. 4 00:00:09,180 --> 00:00:14,250 So in this video you're going to learn how to use the HM command to delete files, and you're also going 5 00:00:14,250 --> 00:00:20,160 to learn how to use the r m command along with wild cards to make the r m command even more powerful. 6 00:00:20,220 --> 00:00:24,330 By the end of this video, you'll know how to delete files using the command line, and in the next 7 00:00:24,330 --> 00:00:27,270 video we'll move our discussion onto directories. 8 00:00:27,270 --> 00:00:30,150 So let's go ahead and get right into it. 9 00:00:31,230 --> 00:00:31,920 All right. 10 00:00:31,920 --> 00:00:38,100 So let's kick off by creating a file called Delete Me in our home directory so we can see that we're 11 00:00:38,100 --> 00:00:39,360 already in our home directory. 12 00:00:39,360 --> 00:00:42,870 By looking at our shell prompt, we see the tilde, the squiggle up there, which means we're in the 13 00:00:42,870 --> 00:00:43,500 shell prompt. 14 00:00:43,500 --> 00:00:48,750 But to confirm we could just type the command print working directory and see that we are indeed in 15 00:00:48,750 --> 00:00:49,800 our home folder. 16 00:00:49,800 --> 00:00:51,930 So let's create a file called Delete Me. 17 00:00:51,930 --> 00:00:56,700 We're going to use the touch command and type delete me and press enter. 18 00:00:56,700 --> 00:01:02,520 And now if we use the LS command, we'll see that we do indeed have a file called Delete Me been created. 19 00:01:02,540 --> 00:01:07,740 We can confirm this of course by opening up our graphical file browser and we'll see a file called Delete 20 00:01:07,740 --> 00:01:08,040 Me. 21 00:01:08,070 --> 00:01:10,800 Okay, so so far so good clearing the screen. 22 00:01:11,370 --> 00:01:15,390 Now that we've created Delete Me, how can we actually delete it? 23 00:01:15,390 --> 00:01:15,810 Okay. 24 00:01:16,200 --> 00:01:21,780 Well, the way to actually delete or remove that file is using something called the r m command. 25 00:01:21,780 --> 00:01:29,490 Now the r m command is r m stands for remove and all you've got to do is give the m command a set of 26 00:01:29,490 --> 00:01:31,920 paths to files that you actually want to delete. 27 00:01:31,920 --> 00:01:34,230 And these could be absolute paths or relative paths. 28 00:01:34,230 --> 00:01:39,810 So if we open up the main page for the R m command, it says that you can give it more than one file. 29 00:01:40,050 --> 00:01:43,680 You see, you can give it a file and then it's got three dots after it. 30 00:01:43,680 --> 00:01:51,420 And we know from our discussion of command line syntax or command line layout that these three dots 31 00:01:51,720 --> 00:01:53,370 mean you can have more than one. 32 00:01:53,370 --> 00:01:57,090 And if you need a refresher on that, check the cheat sheet in the previous section. 33 00:01:57,090 --> 00:01:59,070 It's got all that information in there for you. 34 00:01:59,070 --> 00:02:05,820 So let's go ahead and remove delete me so I could because I'm already in the same folder. 35 00:02:05,820 --> 00:02:10,470 I could just use the relative path like that or delete me. 36 00:02:10,470 --> 00:02:15,360 And when I press enter we'll see that delete me has indeed been deleted. 37 00:02:16,020 --> 00:02:22,050 I could if I create delete me if I create, delete me in our documents folder this time. 38 00:02:22,140 --> 00:02:22,390 Okay. 39 00:02:22,530 --> 00:02:26,520 So if we're looking at our documents folder, we see delete me has been created at the minute in the 40 00:02:26,520 --> 00:02:27,060 command line. 41 00:02:27,060 --> 00:02:32,610 I'm just in the home folder so if I try to do RMM delete me, that won't work because there is no such 42 00:02:32,610 --> 00:02:35,280 thing as delete me in this in this directory. 43 00:02:35,280 --> 00:02:36,270 So delete it. 44 00:02:36,270 --> 00:02:39,570 I have to do our m documents slash delete me. 45 00:02:39,570 --> 00:02:43,050 So I have to give it the path relative to where we are now, which is the home folder. 46 00:02:43,050 --> 00:02:47,520 So here I am in the home folder to get to delete me I have to do documents then delete me. 47 00:02:47,880 --> 00:02:48,220 Okay. 48 00:02:48,270 --> 00:02:54,450 So document slash, delete me and I press enter and then it gets deleted and you can have more than 49 00:02:54,450 --> 00:02:54,780 one. 50 00:02:54,780 --> 00:03:01,680 So if I go ahead and create a file called let's say file one dot txt that's in our home directory, 51 00:03:01,710 --> 00:03:05,310 I create a file called file two in our documents. 52 00:03:05,310 --> 00:03:12,660 So a file two point text in our documents and I create a file called file three dot txt in our downloads. 53 00:03:12,840 --> 00:03:18,540 So I've got one in the home folder, one in the documents and one in downloads. 54 00:03:18,990 --> 00:03:20,430 So delete all those. 55 00:03:20,430 --> 00:03:21,870 I can just enter them one after another. 56 00:03:21,870 --> 00:03:24,480 So I do m file one txt. 57 00:03:24,480 --> 00:03:28,710 I don't have to do anything because that will do because I'm already in the home directory. 58 00:03:28,710 --> 00:03:35,340 The same folder as the document slash file two and downloads slash file three. 59 00:03:35,340 --> 00:03:38,640 And if I press enter, you see the file one disappeared. 60 00:03:38,970 --> 00:03:43,350 File two has disappeared from documents and file three has disappeared from downloads. 61 00:03:43,350 --> 00:03:48,330 So the R command is a very simple command to use for files. 62 00:03:48,330 --> 00:03:50,670 Just think of it as the opposite of the touch command. 63 00:03:50,670 --> 00:03:53,580 So if you want to create a file, you do touch file one. 64 00:03:53,580 --> 00:03:59,100 If you want to delete it, our M to our M file one and it'll work just like that. 65 00:03:59,490 --> 00:04:05,130 So now that we've seen how to use the r m command in a basic way, let's take it up a notch and use 66 00:04:05,130 --> 00:04:06,540 it along with wild cards. 67 00:04:06,540 --> 00:04:11,100 Now, wild cards can really level up the power that your commands have. 68 00:04:11,100 --> 00:04:12,090 So let's just see. 69 00:04:12,120 --> 00:04:14,040 See how we do this using the r m command. 70 00:04:14,190 --> 00:04:15,480 Let's make a few new files. 71 00:04:15,630 --> 00:04:23,490 Let's make a file one txt let's make file two dot pmg and file three jpg. 72 00:04:23,490 --> 00:04:28,440 So when I press enter, you see that all three of those have been created in our home folder. 73 00:04:28,470 --> 00:04:35,730 Okay, now how would we delete every single one of them that ended in dot txt? 74 00:04:35,730 --> 00:04:36,600 So that's actually just for now. 75 00:04:36,600 --> 00:04:39,480 Let's make another one file for txt. 76 00:04:39,690 --> 00:04:45,690 So we've got to the end in txt and we've got one that ends in PNG and one that ends in jpg. 77 00:04:45,720 --> 00:04:46,740 How would we delete them? 78 00:04:47,010 --> 00:04:48,750 They're the ones that end in txt. 79 00:04:49,110 --> 00:04:52,710 Well, first of all, we could do it manually. 80 00:04:52,710 --> 00:04:57,090 We could say ah rm file one txt and file for txt. 81 00:04:57,120 --> 00:04:57,690 That would work. 82 00:04:57,690 --> 00:04:59,820 But I want a bit more of a clever solution than that. 83 00:04:59,930 --> 00:05:03,680 I want to say delete every file that ends in dot txt. 84 00:05:04,490 --> 00:05:11,330 Now the way we do that is by giving the command a pattern and anything that matches this pattern will 85 00:05:11,330 --> 00:05:13,800 be added as a command line argument to it. 86 00:05:13,820 --> 00:05:18,320 So if I the pattern that I'm going to use is this star dot txt. 87 00:05:18,350 --> 00:05:19,400 Let us break this down. 88 00:05:19,880 --> 00:05:22,520 So the star means anything. 89 00:05:22,580 --> 00:05:23,960 Anything could go there. 90 00:05:23,960 --> 00:05:25,370 So this whole thing is our pattern. 91 00:05:25,880 --> 00:05:27,470 The star means anything. 92 00:05:27,470 --> 00:05:29,600 And then dot txt. 93 00:05:29,630 --> 00:05:34,010 So what this means is for anything to match that pattern. 94 00:05:34,370 --> 00:05:36,860 All it has to do is end in dot txt. 95 00:05:37,190 --> 00:05:42,530 So basically what this is saying is remove everything that ends in dot txt and we press enter on that. 96 00:05:42,860 --> 00:05:48,680 You see that file one and file four have been deleted because they ended in dot text. 97 00:05:49,670 --> 00:05:55,010 So let's let's try and see if we could make some other files. 98 00:05:55,010 --> 00:06:00,770 Let's make, let's make file one dot txt again and file for dot dot txt. 99 00:06:00,800 --> 00:06:05,900 Let's make those back and then then let's let's create some of the files. 100 00:06:05,950 --> 00:06:17,990 Okay, let's create some called qibla dot txt and sublime one and then qibla two dot png and qibla three 101 00:06:17,990 --> 00:06:19,250 dot jpg. 102 00:06:19,700 --> 00:06:19,960 Okay. 103 00:06:20,060 --> 00:06:24,620 So we've got some that start with qibla and some that start with the word file. 104 00:06:24,650 --> 00:06:25,100 Okay. 105 00:06:25,190 --> 00:06:29,630 How would we delete the ones that just start with the word file? 106 00:06:29,870 --> 00:06:34,230 Well, the way that we do this is we would use the ram command again. 107 00:06:34,250 --> 00:06:35,540 Of course, because we need to delete. 108 00:06:35,540 --> 00:06:37,360 Then we need to give it another pattern. 109 00:06:37,370 --> 00:06:44,840 So let's think how how would we create a pattern that would match anything as long as it started with 110 00:06:44,840 --> 00:06:45,770 the word file? 111 00:06:46,750 --> 00:06:51,550 Well, the way we could do that is we could type the word file and then put a star, because this means 112 00:06:51,550 --> 00:06:55,450 as long as it starts with file and then has anything after it, it matches. 113 00:06:55,450 --> 00:06:57,280 So all it has to do is start with the word file. 114 00:06:57,280 --> 00:07:00,880 And if I press enter, we see that file one, two, three and four. 115 00:07:02,230 --> 00:07:03,790 Doesn't matter about the file extension or anything. 116 00:07:03,790 --> 00:07:05,800 As long as they start with file, they've been deleted. 117 00:07:05,800 --> 00:07:09,970 But all of the problems have been kept there. 118 00:07:10,810 --> 00:07:14,350 So let's let's create file one, two, three and four again. 119 00:07:14,350 --> 00:07:22,390 So we're going to create touch file one txt file two dot png, file three dot jpg and file for txt will 120 00:07:22,390 --> 00:07:23,320 make them back again. 121 00:07:23,360 --> 00:07:23,820 Okay. 122 00:07:23,950 --> 00:07:30,490 Now we want to delete all of the files that have the number two in them. 123 00:07:31,360 --> 00:07:31,870 Okay. 124 00:07:31,870 --> 00:07:33,340 So how would we do that? 125 00:07:33,370 --> 00:07:40,420 Well, what we might do is we might say, okay, let's remove it. 126 00:07:40,420 --> 00:07:44,470 Doesn't matter what it starts with, but it's got to have the two in there and it doesn't matter what 127 00:07:44,470 --> 00:07:45,160 it ends in. 128 00:07:46,060 --> 00:07:46,690 So here we are. 129 00:07:46,690 --> 00:07:51,100 We're saying it could have anything, then the number two and then anything afterwards. 130 00:07:51,340 --> 00:07:56,290 So if we do that, we see that file two has been deleted and problem two has been deleted, but all 131 00:07:56,290 --> 00:07:57,640 the others are okay. 132 00:07:57,910 --> 00:08:02,680 What about getting rid of the ones that end in jpg? 133 00:08:02,920 --> 00:08:07,810 Well, to do that you just do our m ends in jpg. 134 00:08:07,840 --> 00:08:15,250 I press enter file three dot jpg and three have been deleted, but all the others that end in txt are 135 00:08:15,250 --> 00:08:15,770 still there. 136 00:08:15,790 --> 00:08:17,110 What about deleting those? 137 00:08:17,110 --> 00:08:22,690 Ah m everything that ends in dot txt press enter and they've all been deleted as well. 138 00:08:22,690 --> 00:08:28,600 So you can see here how wildcards can really make the your commands a whole lot more powerful and a 139 00:08:28,600 --> 00:08:29,860 lot more specific. 140 00:08:29,890 --> 00:08:31,070 There's one more that I want to show you. 141 00:08:31,090 --> 00:08:32,020 Let's just go up here. 142 00:08:32,740 --> 00:08:41,500 We've made back our files and let's make back ash blam ash files sublime two dot png, i think. 143 00:08:41,500 --> 00:08:41,690 Yep. 144 00:08:41,720 --> 00:08:44,710 And problem three dot jpg. 145 00:08:45,310 --> 00:08:49,510 Now what if we wanted to get rid of the ones that had two or three in them? 146 00:08:49,810 --> 00:08:53,520 Well, to do that, remember how we got rid of the one that had two in it? 147 00:08:54,040 --> 00:08:58,030 We said it could start with anything, then have a two, then ending anything. 148 00:08:58,120 --> 00:09:00,130 Well, now we want to give it some options. 149 00:09:00,130 --> 00:09:02,500 And this is where the square brackets come in. 150 00:09:02,500 --> 00:09:09,880 So if I said, okay, something like that, that's saying it could start with anything, then have either 151 00:09:09,880 --> 00:09:12,550 a two or three and then ending anything. 152 00:09:12,790 --> 00:09:17,380 So this should get rid of file two, file three and Sjoblom two and Sjoblom three. 153 00:09:17,380 --> 00:09:23,650 So if I press enter, there are file two and file three and problem two and should blam three have been 154 00:09:23,650 --> 00:09:24,400 deleted? 155 00:09:24,400 --> 00:09:30,580 So wildcards are incredible tools that really allow you to control what's going on when you use your 156 00:09:30,580 --> 00:09:36,100 commands, and anything that matches this pattern will be passed as a command line argument to the command 157 00:09:36,100 --> 00:09:37,690 that you use the wildcards for. 158 00:09:37,690 --> 00:09:40,300 So that's a bit of wildcards in action as well. 159 00:09:41,610 --> 00:09:43,080 So there you have it. 160 00:09:43,110 --> 00:09:45,450 In this video you learnt about the Rim Command. 161 00:09:45,480 --> 00:09:49,710 Now the Rim Command is the command that's used to remove stuff from your file system. 162 00:09:49,710 --> 00:09:53,530 And in this video we focus specifically on deleting files. 163 00:09:53,550 --> 00:09:59,280 You also built upon what you learned in the last video about wild cards and saw wild cards being used 164 00:09:59,280 --> 00:10:02,430 in action to delete files. 165 00:10:02,460 --> 00:10:07,770 Now, what you saw about wild cards in this video, it doesn't only apply to the M command. 166 00:10:07,770 --> 00:10:14,280 What you learned about wild cards and how you might do specific tasks works for any command you build 167 00:10:14,280 --> 00:10:19,740 patterns called regular expressions with wild cards and whatever matches those patterns is passed as 168 00:10:19,740 --> 00:10:22,890 a command line argument to the command that you're using. 169 00:10:22,890 --> 00:10:23,790 So there you are. 170 00:10:23,800 --> 00:10:26,340 You've seen some wild cards in practice as well. 171 00:10:26,940 --> 00:10:30,090 Up next, what we're going to be doing is we're going to be developing this discussion a bit more and 172 00:10:30,090 --> 00:10:35,460 we're going to move on to looking at how you might delete directories, how can you delete folders? 173 00:10:35,460 --> 00:10:37,380 So that's a that's a completely next level. 174 00:10:37,380 --> 00:10:38,520 It's going to be very exciting stuff. 175 00:10:38,520 --> 00:10:40,590 So I'll see you in the next video.