1 00:00:00,000 --> 00:00:01,929 [No audio] 2 00:00:01,929 --> 00:00:04,854 File Maintenance Commands. In this lesson, we will cover 3 00:00:04,892 --> 00:00:06,929 a few of the commands that are used to 4 00:00:06,980 --> 00:00:10,350 maintain or keep or change your files. 5 00:00:10,850 --> 00:00:13,218 Some of the commands are listed here. 6 00:00:13,364 --> 00:00:15,465 The first one is the copy command, 7 00:00:15,538 --> 00:00:19,159 cp, which copies one file to another. 8 00:00:19,850 --> 00:00:23,430 The second one is to remove a file which is, rm. 9 00:00:24,170 --> 00:00:26,142 The third one is move, 10 00:00:26,275 --> 00:00:30,573 this command is used to move the location of a file 11 00:00:30,621 --> 00:00:35,133 from one location to another or to rename a file. 12 00:00:35,181 --> 00:00:38,877 So it does two things or it serves two purpose. 13 00:00:39,034 --> 00:00:44,298 Then we have mkdir which is to make directory and then 14 00:00:44,444 --> 00:00:48,597 rmdir to remove a directory or there's another way to remove 15 00:00:48,633 --> 00:00:53,959 a directory by typing rm -r or hyphen r. 16 00:00:54,349 --> 00:00:58,209 Then we have change group which is the ownership 17 00:00:58,270 --> 00:01:02,057 of a file at the group level, and then 18 00:01:02,083 --> 00:01:05,417 we have change ownership which is the ownership of 19 00:01:05,444 --> 00:01:08,297 the file at the user level. 20 00:01:08,444 --> 00:01:11,501 Some of the commands we have already covered and some 21 00:01:11,515 --> 00:01:14,241 of the commands we will be covering in this lesson. 22 00:01:14,386 --> 00:01:19,194 So let's go to our Linux machine and go over these 23 00:01:19,232 --> 00:01:20,633 commands one by one, 24 00:01:20,633 --> 00:01:23,720 [No audio] 25 00:01:23,720 --> 00:01:25,994 and let's log into our machine. 26 00:01:25,994 --> 00:01:28,005 We already have the last screen open. 27 00:01:28,068 --> 00:01:29,519 Let's clear this out. 28 00:01:29,910 --> 00:01:31,041 Where are we? 29 00:01:31,115 --> 00:01:32,258 We are in etc. 30 00:01:32,293 --> 00:01:35,389 When you type cd, and hit enter, and then pwd, 31 00:01:35,449 --> 00:01:37,430 now you are back in your home directory. 32 00:01:37,550 --> 00:01:40,202 Clear the page,so this way you will start fresh. 33 00:01:40,346 --> 00:01:41,722 Now the first command that 34 00:01:41,736 --> 00:01:43,510 we will be learning is cp. 35 00:01:43,949 --> 00:01:45,554 Again cp is a copy command. 36 00:01:45,601 --> 00:01:49,045 You could find out by hitting man and cp. 37 00:01:49,178 --> 00:01:54,250 This will tell you cp copy files and directories. 38 00:01:54,690 --> 00:01:58,641 So the way you could do it in Windows is you 39 00:01:58,776 --> 00:02:02,793 right click on a file and you get the option of 40 00:02:02,832 --> 00:02:06,382 copy and then you go to another file, another directory or 41 00:02:06,396 --> 00:02:10,250 another location and then right click and do the paste. In Linux, 42 00:02:10,309 --> 00:02:11,565 this is how it works. 43 00:02:11,747 --> 00:02:16,901 We will, let's look at our listing. 44 00:02:17,046 --> 00:02:18,389 We have all these files. 45 00:02:18,449 --> 00:02:23,630 So now we will copy the file called george 46 00:02:24,190 --> 00:02:29,533 and we will name it to a different name, 47 00:02:29,572 --> 00:02:32,860 let's say another character of the show 48 00:02:33,429 --> 00:02:36,399 david, and you hit enter. 49 00:02:36,729 --> 00:02:40,477 So this will tell you that cp space source which 50 00:02:40,503 --> 00:02:43,410 is the george, and the destination which is the david. 51 00:02:43,470 --> 00:02:47,389 You hit enter, then you do ls -ltr. 52 00:02:48,130 --> 00:02:50,634 The tr option will give you the newest 53 00:02:50,682 --> 00:02:52,934 file created at the bottom, hit enter. 54 00:02:53,091 --> 00:02:56,526 So the david file is created. If you also notice, 55 00:02:56,658 --> 00:03:00,757 the george file is still there, and it created a 56 00:03:00,783 --> 00:03:05,330 file, copied the file george and renamed it david. 57 00:03:06,369 --> 00:03:10,085 We could also add something to the file 58 00:03:10,158 --> 00:03:12,259 as let's say echo 59 00:03:12,259 --> 00:03:14,227 [No audio] 60 00:03:14,227 --> 00:03:16,897 david puddy, 61 00:03:16,897 --> 00:03:18,897 [No audio] 62 00:03:18,897 --> 00:03:24,253 is Eliane's boy friend 63 00:03:24,253 --> 00:03:26,755 [No audio] 64 00:03:26,755 --> 00:03:31,865 and then we'll output to david, and hit enter. 65 00:03:32,048 --> 00:03:33,317 And how do you verify it? 66 00:03:33,343 --> 00:03:35,130 You do cat david. 67 00:03:35,690 --> 00:03:38,300 You will see the contents in there. 68 00:03:39,169 --> 00:03:42,065 That's what you do the copy for, you could 69 00:03:42,128 --> 00:03:48,089 also do, is you copy david, and then you 70 00:03:48,139 --> 00:03:51,018 can copy it not at this location where you 71 00:03:51,044 --> 00:03:52,858 are, you could copy it some other location. 72 00:03:52,893 --> 00:03:56,805 Let's say we wanted to copy into tmp location. 73 00:03:56,998 --> 00:03:58,841 So it is going to copy it. 74 00:03:58,856 --> 00:04:00,141 It's now going to remove that file. 75 00:04:00,166 --> 00:04:02,781 It will copy it to the tmp directory. 76 00:04:02,865 --> 00:04:06,501 Hit enter, do ls -ltr. 77 00:04:06,645 --> 00:04:08,218 You'll see it has the david 78 00:04:08,253 --> 00:04:09,617 copy, the original copy here. 79 00:04:09,703 --> 00:04:12,977 Now we will go to /tmp, and then we will 80 00:04:13,003 --> 00:04:16,361 do ls -ltr at the bottom to see the file is there. 81 00:04:16,494 --> 00:04:18,574 See the same file that we copied 82 00:04:18,622 --> 00:04:20,313 but it's in a different location, 83 00:04:20,481 --> 00:04:22,338 and it is owned by me, 84 00:04:22,483 --> 00:04:25,014 owned by the same group as myself, 85 00:04:25,171 --> 00:04:27,634 and it has same number of bytes. 86 00:04:27,742 --> 00:04:30,161 You could do cat and david to 87 00:04:30,175 --> 00:04:32,134 see what's inside of the file. 88 00:04:32,242 --> 00:04:33,869 So which directory you are in? 89 00:04:33,980 --> 00:04:35,325 We are in tmp directory. 90 00:04:35,398 --> 00:04:36,402 If you want to go back to 91 00:04:36,415 --> 00:04:38,182 our home directly, just simply type cd, 92 00:04:38,265 --> 00:04:40,697 hit enter, pwd, and you are 93 00:04:40,723 --> 00:04:43,294 back in your home directory, ls -ltr. 94 00:04:43,462 --> 00:04:44,981 And that's where you have your 95 00:04:45,055 --> 00:04:47,421 all the files. That's about the copy. 96 00:04:47,506 --> 00:04:49,253 You could practice that copy command by 97 00:04:49,291 --> 00:04:51,321 copying different files or different names, 98 00:04:51,406 --> 00:04:52,626 whichever names that you like. 99 00:04:52,687 --> 00:04:54,989 The next command we're going to learn is remove. 100 00:04:55,549 --> 00:04:58,459 Let's create another file touch, 101 00:04:58,850 --> 00:05:04,485 and we will create a new file in homer, bard, marge, 102 00:05:04,558 --> 00:05:08,850 lisa, and we call another file apoho. 103 00:05:09,410 --> 00:05:13,085 apoho is another character of Simpsons family. 104 00:05:13,268 --> 00:05:16,890 So we'll create this file called apoho. 105 00:05:17,209 --> 00:05:19,242 And we will do ls -ltr, 106 00:05:19,316 --> 00:05:22,966 and you'll see it created a file apoho. 107 00:05:23,097 --> 00:05:25,553 If you want to append a file or add 108 00:05:25,592 --> 00:05:27,186 something to that file, what do we do? 109 00:05:27,247 --> 00:05:37,821 We do echo, apoho is an indian character in the show. 110 00:05:37,955 --> 00:05:41,829 Right. So I'll put that to where, apoho. 111 00:05:42,269 --> 00:05:46,123 How do you verify that, apoho, apoho an indian character in the show. 112 00:05:46,123 --> 00:05:49,342 That's how you do it. Now you want to remove this file. Now, 113 00:05:49,415 --> 00:05:51,477 after certain times you don't need it. 114 00:05:51,563 --> 00:05:57,937 So what you do, you do rm apoho, simply 115 00:05:57,973 --> 00:06:01,497 as that, hit enter, and it's gone. Let's try, 116 00:06:01,584 --> 00:06:03,730 let's make sure it's gone or not. Yes. 117 00:06:03,779 --> 00:06:08,006 See there is no such file apoho in our directory, 118 00:06:08,138 --> 00:06:09,720 because we removed it. 119 00:06:10,410 --> 00:06:12,410 We could also remove a directory, 120 00:06:12,470 --> 00:06:14,649 but we'll cover that when it's turns going to come. 121 00:06:14,700 --> 00:06:16,881 The next command we have to learn is move. 122 00:06:17,015 --> 00:06:18,566 Now move command, 123 00:06:18,757 --> 00:06:21,458 actually move the file from one location 124 00:06:21,493 --> 00:06:24,302 to another and also rename the file. 125 00:06:24,446 --> 00:06:27,578 How does it work? Let's call lex, in Superman 126 00:06:27,614 --> 00:06:28,514 there is this character, 127 00:06:28,562 --> 00:06:31,497 of course it's a villain character, lex. So let's see, 128 00:06:31,523 --> 00:06:32,738 we have the lex. 129 00:06:32,894 --> 00:06:33,993 Yes, we have there. 130 00:06:34,092 --> 00:06:36,950 We wanted to rename that to luther. 131 00:06:37,070 --> 00:06:39,933 So lex, last name was luther. So let's try, 132 00:06:39,971 --> 00:06:42,321 we wanted to change to Luther. So how do we do it? 133 00:06:42,335 --> 00:06:46,477 We do mv lex, and this is of course the source, 134 00:06:46,514 --> 00:06:48,489 and what's the destination name you want to give it to, 135 00:06:48,540 --> 00:06:51,562 luther, luther. 136 00:06:51,756 --> 00:06:53,829 This is going to rename this 137 00:06:53,880 --> 00:06:55,502 file within the same directory. 138 00:06:55,585 --> 00:06:59,242 Hit enter, ls -ltr, 139 00:06:59,436 --> 00:07:01,717 and here you see luther. 140 00:07:01,873 --> 00:07:04,200 So this is how you rename it. 141 00:07:05,190 --> 00:07:06,993 If you wanted to rename any 142 00:07:07,092 --> 00:07:09,705 other file, you could do that, 143 00:07:09,768 --> 00:07:11,097 or you wanted to create a 144 00:07:11,123 --> 00:07:12,634 different file, you could do that. 145 00:07:12,671 --> 00:07:17,485 Let's say we have this file called david, 146 00:07:17,558 --> 00:07:20,014 and we want to change to the last name 147 00:07:20,052 --> 00:07:25,089 of course, which is mv david to puddy. 148 00:07:26,309 --> 00:07:27,514 So that's his last name. 149 00:07:27,552 --> 00:07:30,697 So we are moving david to the name puddy. 150 00:07:30,854 --> 00:07:32,390 Let's ls -ltr. 151 00:07:32,510 --> 00:07:35,294 It changed the name from david to puddy, 152 00:07:35,402 --> 00:07:39,502 but it kept the content of that file, which was if 153 00:07:39,515 --> 00:07:42,854 you do cat, you'll see david puddy is Eliane's boy friend. 154 00:07:42,962 --> 00:07:44,037 So it just changed the name. 155 00:07:44,063 --> 00:07:45,359 It didn't change the content. 156 00:07:46,350 --> 00:07:49,381 Next one, by the way, also to change the location 157 00:07:49,466 --> 00:07:54,601 is if you wanted to move puddy from this location 158 00:07:54,686 --> 00:07:58,834 to a different location, let's say to tmp, it will 159 00:07:58,872 --> 00:08:02,377 move that file to a different location tmp. 160 00:08:02,414 --> 00:08:04,441 Now let's see do we still have that file? 161 00:08:04,585 --> 00:08:06,585 No, we don't. Where did it go? 162 00:08:06,648 --> 00:08:07,933 We moved it to tmp. 163 00:08:08,041 --> 00:08:10,022 So how do we know it moved to tmp? 164 00:08:10,105 --> 00:08:13,929 You do cd into tmp, ls -ltr. 165 00:08:14,250 --> 00:08:18,674 See, this is the puddy file that you created. 166 00:08:18,842 --> 00:08:24,217 Now let's move puddy back to our home directory. 167 00:08:24,253 --> 00:08:26,078 And what is our home directory? 168 00:08:26,234 --> 00:08:28,380 You guys should know that home, 169 00:08:28,709 --> 00:08:31,713 your username, and hit enter. 170 00:08:31,872 --> 00:08:34,716 It should bring you back to your home directory. 171 00:08:34,812 --> 00:08:36,705 When you do cd, hit enter, 172 00:08:36,768 --> 00:08:38,294 it will bring you back to your home directory. 173 00:08:38,341 --> 00:08:41,408 Do ls -ltr, and your puddy file is back. 174 00:08:41,580 --> 00:08:43,466 Next one is make directory. 175 00:08:43,596 --> 00:08:50,745 It's simply we will make mkdir gameofthrone, one of the biggest show, 176 00:08:50,807 --> 00:08:54,285 how's that. We created this, 177 00:08:54,288 --> 00:08:57,789 this is how the new directory is created mkdir. 178 00:08:58,169 --> 00:09:02,210 Now let's try command which is remove directory. 179 00:09:02,330 --> 00:09:03,638 So remove directory, 180 00:09:03,734 --> 00:09:04,966 if you want to delete one of 181 00:09:04,968 --> 00:09:08,469 these directories from your home directory, 182 00:09:09,090 --> 00:09:11,653 let's say I wanted to remove gameofthrone directory. 183 00:09:11,762 --> 00:09:17,101 You just simply type rmdir gameofthrone, 184 00:09:17,101 --> 00:09:19,822 and it is gone. 185 00:09:19,955 --> 00:09:23,265 This is one way to remove it. Another way to remove it, 186 00:09:23,328 --> 00:09:25,666 in order for us to remove it, let's recreate it again, 187 00:09:25,728 --> 00:09:27,297 hit up arrow key, and you will 188 00:09:27,323 --> 00:09:28,693 get back to the same command. 189 00:09:28,742 --> 00:09:33,434 mdir gameofthrone, the directory is created. 190 00:09:33,481 --> 00:09:40,080 Another way to remove it is rm -r gameofthrone, and it is gone. 191 00:09:40,080 --> 00:09:47,916 [No audio] 192 00:09:47,950 --> 00:09:50,500 All right. Next command we have change group. 193 00:09:51,130 --> 00:09:55,309 Changing group is changing the ownership of the file, 194 00:09:55,630 --> 00:09:58,961 changing the ownership of a group of a file. 195 00:09:59,046 --> 00:10:01,098 And the last command is changing 196 00:10:01,133 --> 00:10:03,270 the ownership of a file. 197 00:10:03,330 --> 00:10:06,409 So if I wanted to change the ownership of file 198 00:10:06,849 --> 00:10:11,440 puddy and I wanted to change it to group called 199 00:10:11,830 --> 00:10:16,810 root, so we will do chgrp root puddy. 200 00:10:17,950 --> 00:10:21,169 It says, Operation not permitted. Why? 201 00:10:21,340 --> 00:10:25,085 Because who we are, we are ourselves. 202 00:10:25,218 --> 00:10:27,073 And who can make these changes? 203 00:10:27,171 --> 00:10:29,138 If I wanted to assign something to 204 00:10:29,164 --> 00:10:30,929 root, I have to be root. 205 00:10:31,109 --> 00:10:32,750 So let's become root. 206 00:10:32,750 --> 00:10:37,369 [No audio] 207 00:10:37,369 --> 00:10:40,349 Once you're root, let's go back to our home directory. 208 00:10:40,349 --> 00:10:43,469 [No audio] 209 00:10:43,469 --> 00:10:49,489 And now what we'll is do chgrp root puddy. 210 00:10:49,669 --> 00:10:53,710 And this time it worked, because we have all 211 00:10:53,760 --> 00:10:56,349 permissions in the world we could think of. 212 00:10:56,460 --> 00:11:01,969 Now, next command change ownership to root of puddy. 213 00:11:02,090 --> 00:11:04,317 This will change the ownership of the 214 00:11:04,403 --> 00:11:07,080 file name puddy to root as well. 215 00:11:07,950 --> 00:11:11,409 Now, if you wanted to do both commands at once 216 00:11:11,460 --> 00:11:18,193 so chown, you could do, iafzal:iafzal puddy. 217 00:11:18,231 --> 00:11:20,814 So what this command will do, it will change the ownership 218 00:11:20,861 --> 00:11:23,598 as well as group ownership of the file name puddy. 219 00:11:23,754 --> 00:11:27,278 Hit enter, ls -ltr, and there you go. 220 00:11:27,304 --> 00:11:28,718 You got your file back with the 221 00:11:28,744 --> 00:11:31,505 original permission or original ownership permission. 222 00:11:31,578 --> 00:11:33,593 So these are the file maintenance command. 223 00:11:33,642 --> 00:11:38,729 Once again the recap, cp, rm, mv, mkdir, 224 00:11:38,849 --> 00:11:42,502 rmdir, chgrp, chown. 225 00:11:42,502 --> 00:11:44,213 [No audio]