1 00:00:00,240 --> 00:00:01,710 Hello the beautiful people. 2 00:00:01,710 --> 00:00:06,390 And welcome to this video where we're going to be finishing off our discussion of how to delete files 3 00:00:06,390 --> 00:00:08,790 and directories using the command line. 4 00:00:08,790 --> 00:00:15,180 So in this video you're going to learn how to use the R, m and RMD commands to delete folders. 5 00:00:15,180 --> 00:00:19,080 And by the end of this video you'll know pretty much everything you need to know about deleting files 6 00:00:19,080 --> 00:00:21,210 and folders using the command line. 7 00:00:21,210 --> 00:00:23,400 So let's go ahead and get right into it. 8 00:00:25,150 --> 00:00:31,720 All right, so let's start off by creating a folder in our home directory called Dell Folder. 9 00:00:31,720 --> 00:00:38,680 So if I use the mkdir command and type del folder, we'll see that we created a new folder inside our 10 00:00:38,680 --> 00:00:40,510 home directory called del folder. 11 00:00:40,930 --> 00:00:42,250 So let's remove it. 12 00:00:42,250 --> 00:00:42,520 Okay. 13 00:00:42,520 --> 00:00:47,140 Now all we have to do actually to remove it is use the r m command again. 14 00:00:47,140 --> 00:00:50,650 So if I use r m and use del folder and press enter. 15 00:00:52,140 --> 00:00:53,890 We actually get an error. 16 00:00:53,910 --> 00:01:01,020 Now, this is because yes, we will use the RGM command, but in order for the command to remove folders, 17 00:01:01,020 --> 00:01:04,870 we need to give the r m command the r option. 18 00:01:04,890 --> 00:01:08,820 Now the R option stands for recursive or recursively. 19 00:01:08,850 --> 00:01:15,270 Now, if you delete something recursively, that means that your delete that thing and everything else 20 00:01:15,270 --> 00:01:16,340 inside of it. 21 00:01:16,350 --> 00:01:23,130 So if we try that now our M slash R and then del folder and press enter, we'll see. 22 00:01:23,130 --> 00:01:26,570 Now that del folder has indeed been deleted. 23 00:01:26,580 --> 00:01:27,600 So let's make it again. 24 00:01:27,690 --> 00:01:28,110 Make it again. 25 00:01:28,110 --> 00:01:33,900 Let's make Del folder and let's make some more folders inside of it. 26 00:01:33,900 --> 00:01:35,910 So we're going to use brace expansion for this. 27 00:01:35,910 --> 00:01:42,930 Now we can do make make directory del folder and inside there we're going to make three folders called 28 00:01:42,930 --> 00:01:44,970 delete me one, two and three. 29 00:01:44,970 --> 00:01:45,450 Okay. 30 00:01:45,450 --> 00:01:50,100 So if I press enter and take a look at Del folder, we can see we've got delete me one, delete me two 31 00:01:50,100 --> 00:01:51,060 and delete me three. 32 00:01:51,060 --> 00:01:57,720 So that's how this work we made first it made delete me one inside of Del folder, then it may delete 33 00:01:57,720 --> 00:01:58,200 me too. 34 00:01:58,200 --> 00:01:59,850 Then it made delete me three. 35 00:02:00,090 --> 00:02:01,680 So that's brace expansion again. 36 00:02:02,130 --> 00:02:05,700 So let's make some files inside each of those. 37 00:02:05,700 --> 00:02:14,130 So if we touch del folder, delete me, delete me, one, two and three and then inside of there, make 38 00:02:14,130 --> 00:02:15,750 file one, two and three. 39 00:02:16,590 --> 00:02:18,900 And now if we take a look we can see and delete me one. 40 00:02:18,900 --> 00:02:24,120 We've got far one, two and three in delete me two file one, two and three and then delete me three. 41 00:02:24,120 --> 00:02:26,040 We've got file one, two and three. 42 00:02:26,040 --> 00:02:32,520 So now if we, if we go ahead and if we just look, we've got Del folder here, we've got Del folder 43 00:02:33,060 --> 00:02:34,200 in our home directory. 44 00:02:34,200 --> 00:02:42,450 Now if we use our M with the R option to delete that del folder, remember to delete something recursively 45 00:02:42,450 --> 00:02:46,230 means to delete it and everything else inside of it. 46 00:02:46,230 --> 00:02:52,230 So if I use our M with the R option and give it del folder and press enter, we'll see. 47 00:02:52,230 --> 00:02:57,510 That del folder has indeed been deleted and so is everything else inside of it. 48 00:02:58,110 --> 00:03:03,690 Now one thing you might notice is that the r m command, when it did that, it actually didn't give 49 00:03:03,690 --> 00:03:04,830 us any warning. 50 00:03:04,830 --> 00:03:09,660 It just went ahead and deleted everything inside the del folder folder. 51 00:03:09,660 --> 00:03:09,970 Okay. 52 00:03:10,140 --> 00:03:16,230 Now because of this, our m dash r m with the r option is a very powerful command that should be dealt 53 00:03:16,230 --> 00:03:20,940 with very carefully, especially when you start using the star wild card as well. 54 00:03:20,940 --> 00:03:25,440 All things can go wrong and you can find yourself just deleting everything and not being able to get 55 00:03:25,440 --> 00:03:27,570 your files back, which is sad, sad times. 56 00:03:27,570 --> 00:03:33,600 So for example, if I do go ahead and do that now, if I just delete that on everything on our system 57 00:03:33,600 --> 00:03:34,320 right now, I'm not going to do it. 58 00:03:34,320 --> 00:03:34,860 I'm joking. 59 00:03:34,860 --> 00:03:42,120 So one way to make the r m command safer is actually to give it the AI option. 60 00:03:42,690 --> 00:03:49,710 So the AI option stands for interactive and this will make the r m command ask you interactively whether 61 00:03:49,710 --> 00:03:52,020 to delete each file or not. 62 00:03:52,050 --> 00:03:57,300 Now, at the moment we don't have we don't have the del folder anymore. 63 00:03:57,300 --> 00:04:03,510 So to make del folder and delete me one, two and three all at once, I'm going to use the mkdir command. 64 00:04:03,510 --> 00:04:08,340 Give it the p option which allows you to create an entire path and do delta and tell it. 65 00:04:08,340 --> 00:04:11,730 Create delete me one, two and three. 66 00:04:11,730 --> 00:04:19,290 So if I do that actually not del two sorry del folder then if I do that I get del folder inside there 67 00:04:19,290 --> 00:04:21,120 delete me one, delete me two and delete me three. 68 00:04:21,180 --> 00:04:24,270 Kind of call right now let's create the files inside there. 69 00:04:24,270 --> 00:04:30,570 So del folder forward slash delete me one, two and three and we're going to make file one, two and 70 00:04:30,570 --> 00:04:30,780 three. 71 00:04:30,780 --> 00:04:34,680 And so each of those and inside each of those, we've got our files back. 72 00:04:35,190 --> 00:04:36,720 So there we are. 73 00:04:36,750 --> 00:04:38,070 Didn't take too long at all. 74 00:04:38,670 --> 00:04:40,080 We've got our files back. 75 00:04:40,560 --> 00:04:43,980 By the way, can you see just how much quicker this is than pointing and clicking? 76 00:04:43,980 --> 00:04:47,910 We created all of those files without ever even needing to enter the folders. 77 00:04:47,910 --> 00:04:50,130 We just created them right from our home directory. 78 00:04:50,220 --> 00:04:51,540 So, so cool. 79 00:04:51,990 --> 00:04:58,890 So now if we try to delete everything again, try and delete del folder by giving VRM Command the R 80 00:04:58,890 --> 00:05:00,540 and I options. 81 00:05:00,780 --> 00:05:02,100 It doesn't matter which order you do it. 82 00:05:02,100 --> 00:05:03,300 So we give it del folder. 83 00:05:03,480 --> 00:05:09,360 We'll see that now it's asking permission for us to actually delete things. 84 00:05:09,360 --> 00:05:12,060 So it's saying Can I go into Del folder? 85 00:05:12,090 --> 00:05:12,600 Let's tell it. 86 00:05:12,600 --> 00:05:16,770 Yes, it will now say can I go into delete me one. 87 00:05:17,880 --> 00:05:21,930 Let's say yes and can I delete a file too. 88 00:05:21,930 --> 00:05:23,670 Yes, you can kind of delete file three. 89 00:05:23,670 --> 00:05:24,240 Yes, you can. 90 00:05:24,240 --> 00:05:26,130 Can I delete file one inside. 91 00:05:26,130 --> 00:05:26,820 Delete me one. 92 00:05:26,820 --> 00:05:27,480 Yes, you can. 93 00:05:28,200 --> 00:05:30,000 Can I remove the directory. 94 00:05:30,000 --> 00:05:30,720 Delete me one. 95 00:05:30,720 --> 00:05:31,590 Yes you can. 96 00:05:31,650 --> 00:05:33,450 Can I go into delete me three. 97 00:05:33,450 --> 00:05:37,200 You see it's not particularly doing it in any order, but it's asking you before it does it. 98 00:05:37,200 --> 00:05:39,960 Okay, so let's say yes, you can delete that. 99 00:05:39,960 --> 00:05:41,280 You can delete that, you can delete that. 100 00:05:41,280 --> 00:05:42,180 Now let's leave. 101 00:05:42,600 --> 00:05:45,570 Let's leave file two inside delete me two. 102 00:05:45,990 --> 00:05:46,740 So it's going to leave. 103 00:05:46,740 --> 00:05:47,640 Delete me three. 104 00:05:47,700 --> 00:05:49,080 Going to delete me two. 105 00:05:49,380 --> 00:05:50,850 No, don't delete file. 106 00:05:50,910 --> 00:05:51,360 Two. 107 00:05:51,720 --> 00:05:52,260 Yes. 108 00:05:52,260 --> 00:05:53,190 Delete file three. 109 00:05:53,190 --> 00:05:53,610 Yes. 110 00:05:53,610 --> 00:05:54,630 Delete file one. 111 00:05:54,780 --> 00:05:56,970 No, don't delete the entire folder. 112 00:05:57,450 --> 00:06:00,360 No, don't delete Dell folder and that's it. 113 00:06:00,750 --> 00:06:06,150 So if we look inside Dell folder, which is C, delete me two and file two still left over. 114 00:06:06,150 --> 00:06:06,510 Okay. 115 00:06:06,510 --> 00:06:07,290 So that's quite cool. 116 00:06:07,290 --> 00:06:07,470 Right. 117 00:06:07,470 --> 00:06:12,900 You can control what the r command deletes, but this is kind of tedious, right? 118 00:06:12,900 --> 00:06:19,470 Saying yes and no every time it's if you had a lot of files that would that would really be a massive 119 00:06:19,470 --> 00:06:20,070 hassle. 120 00:06:20,070 --> 00:06:26,220 So fortunately, there's another command that's specialized for only removing directories that are empty 121 00:06:26,220 --> 00:06:29,070 now because this command only removes empty directories. 122 00:06:29,070 --> 00:06:31,410 This means that you can tell it to delete everything. 123 00:06:31,440 --> 00:06:36,690 It will only delete the folders that are actually empty, which means you'll never delete a file accidentally. 124 00:06:36,690 --> 00:06:41,100 And that command is called the MDR, the remove directory command. 125 00:06:41,100 --> 00:06:47,190 So to see the Remove Directory command in action first let's go ahead and delete everything inside Dell 126 00:06:47,190 --> 00:06:47,610 folder. 127 00:06:47,610 --> 00:06:51,420 So remove recursively Dell folder and there we are. 128 00:06:51,420 --> 00:06:53,520 Dell folder is been deleted. 129 00:06:53,520 --> 00:06:55,470 Now let's go ahead and create some folders. 130 00:06:55,470 --> 00:07:02,400 So we're going to use mkdir with the P option to create a let's call it Dell folder and then folder 131 00:07:02,400 --> 00:07:03,930 1 to 3. 132 00:07:03,930 --> 00:07:04,980 That's another way of doing it. 133 00:07:04,980 --> 00:07:09,600 By the way, you don't have to type one, comma two, comma three, you can just do 1.3. 134 00:07:09,840 --> 00:07:13,890 And if we look in Dell folder, we've got folder one, folder two and folder three. 135 00:07:13,920 --> 00:07:20,610 Okay, and let's put ten folders inside folders one and two, but not in folder one, not in folder 136 00:07:20,610 --> 00:07:20,940 three. 137 00:07:20,940 --> 00:07:30,680 So that's two touch dell folder folder one, two and then put inside there file 1 to 10 txt. 138 00:07:30,900 --> 00:07:34,350 So if we look inside folder one, we've now got ten text files. 139 00:07:34,350 --> 00:07:39,720 We'll look inside folder two, we've got ten text files, but in folder three we don't have any. 140 00:07:40,290 --> 00:07:46,290 So now that we've got three folders inside Dell folder folders, want a folder to have ten files in 141 00:07:46,290 --> 00:07:48,840 them, but folder three is completely empty. 142 00:07:48,840 --> 00:07:57,900 Now if I try to do remove directory and I say remove directory dell folder slash everything. 143 00:07:58,350 --> 00:08:04,770 Okay, what we're saying here is delete everything inside dell folder, delete the empty folders inside 144 00:08:04,770 --> 00:08:05,640 Dell folder basically. 145 00:08:05,640 --> 00:08:07,770 So if I do that, we'll see. 146 00:08:07,770 --> 00:08:11,730 It failed to remove folder one because the directory is not empty. 147 00:08:11,730 --> 00:08:16,680 It failed to remove folder two because the directory is not empty, but folder three has indeed been 148 00:08:16,680 --> 00:08:17,340 deleted. 149 00:08:17,970 --> 00:08:24,930 So just so you know, this wouldn't have worked if we just done remove directory of Dell folder without 150 00:08:24,930 --> 00:08:25,680 putting the star. 151 00:08:25,680 --> 00:08:28,920 So you see we've got the star asterisk wildcard here. 152 00:08:28,920 --> 00:08:33,600 If we just had removed Dell folder, the shell will say but Dell folder is not empty. 153 00:08:33,600 --> 00:08:34,890 How can I just delete it? 154 00:08:34,890 --> 00:08:42,059 But what we did is we said remove everything that is inside Dell folder that is empty. 155 00:08:42,600 --> 00:08:45,390 So we had to have the star there to make that work. 156 00:08:45,390 --> 00:08:47,850 So that's just something to bear in mind. 157 00:08:48,690 --> 00:08:49,080 Okay. 158 00:08:49,080 --> 00:08:54,600 So as one final challenge, in the last video, we created a project folder that had a whole bunch of 159 00:08:54,600 --> 00:08:57,330 other folders inside with like a bajillion files. 160 00:08:57,330 --> 00:08:59,730 Okay, you must remember this from, like, the last few videos. 161 00:09:00,300 --> 00:09:05,730 Now, what I want you to do is I want you to try and delete all of those folders and directories and 162 00:09:05,730 --> 00:09:09,150 files and stuff in one command. 163 00:09:09,420 --> 00:09:10,530 So that's your challenge? 164 00:09:10,530 --> 00:09:11,790 You that's your challenge. 165 00:09:11,790 --> 00:09:15,660 You've got to try and delete that entire project folder with everything inside of it. 166 00:09:15,660 --> 00:09:18,600 All the thousands of files in one command. 167 00:09:18,600 --> 00:09:21,330 So pause the video now and see if you can figure it out. 168 00:09:21,510 --> 00:09:22,380 Figure out how to do it. 169 00:09:22,380 --> 00:09:24,660 Then come back and see how you did. 170 00:09:30,110 --> 00:09:30,980 Did you manage it? 171 00:09:31,010 --> 00:09:32,860 If so, well done. 172 00:09:32,870 --> 00:09:35,020 You learn super, super quick. 173 00:09:35,030 --> 00:09:36,380 So here's how I do it. 174 00:09:36,770 --> 00:09:38,660 Now, the folder was called Project. 175 00:09:38,810 --> 00:09:39,680 It was on the desktop. 176 00:09:39,680 --> 00:09:40,620 So let's shift there. 177 00:09:40,640 --> 00:09:42,860 It's it's called Project. 178 00:09:42,860 --> 00:09:46,220 So we want to delete everything. 179 00:09:46,220 --> 00:09:51,440 So we don't want to use the RMD command because that only deletes empty directories. 180 00:09:51,440 --> 00:09:55,660 We want to use the r m command instead because we want to delete directories that have stuff in them. 181 00:09:56,150 --> 00:10:01,700 Now we want to delete the project folder and everything inside it. 182 00:10:01,700 --> 00:10:04,070 So we need to delete recursively. 183 00:10:04,070 --> 00:10:10,640 So to do that we're going to use the R option and putting that all together basically means we'll just 184 00:10:10,640 --> 00:10:13,970 do remove recursively the project folder. 185 00:10:13,970 --> 00:10:20,300 Or if I was in my home directory like this, I would do remove recursively desktop slash project just 186 00:10:20,300 --> 00:10:22,430 giving the path to that folder. 187 00:10:22,430 --> 00:10:30,410 And when I press enter as if by magic, however many folders there were, the thousands of files have 188 00:10:30,410 --> 00:10:31,400 been deleted. 189 00:10:31,400 --> 00:10:34,310 How absolutely epic is that? 190 00:10:35,400 --> 00:10:41,220 So that'll just about wrap up our discussion of deleting files and folders using the command line. 191 00:10:41,220 --> 00:10:47,430 So in this video you learn that the r m command needs the R option in order to delete folders, and 192 00:10:47,430 --> 00:10:50,700 the R option stands for recursive deleting. 193 00:10:50,700 --> 00:10:56,370 So to delete something recursively means to delete that thing and everything else inside it. 194 00:10:56,370 --> 00:11:01,530 And this is why you need to be especially careful when using the R option because you can end up deleting 195 00:11:01,530 --> 00:11:03,420 stuff that you didn't want to. 196 00:11:04,380 --> 00:11:09,390 Now, one way to make that a bit safer is to use the AI option for the R command, which will allow 197 00:11:09,390 --> 00:11:12,810 the r m command to be interactive when it does its deleting. 198 00:11:12,810 --> 00:11:17,760 So this is where you can say yes or no to each file or folder being deleted. 199 00:11:18,090 --> 00:11:22,500 But the best thing is there's not really much you can rely on. 200 00:11:22,500 --> 00:11:24,930 Just be careful when doing your deleting. 201 00:11:24,930 --> 00:11:25,350 Okay. 202 00:11:25,410 --> 00:11:31,290 But the safest of all options is to use the RMD command which will only delete folders that are empty. 203 00:11:31,290 --> 00:11:35,580 So if you just want to do a bit of tidying up and delete folders that don't have anything in them, 204 00:11:35,580 --> 00:11:40,980 you can use the RMD command and rest assured that you won't delete any data. 205 00:11:41,280 --> 00:11:47,040 So coming up next, we're going to discuss how you might copy and paste files and directories using 206 00:11:47,040 --> 00:11:47,670 the command line. 207 00:11:47,670 --> 00:11:50,700 So instead of cutting our file tree, we're going to make it grow. 208 00:11:50,700 --> 00:11:54,000 So for all that goodness, I'll see you in the next video.