1 00:00:00,180 --> 00:00:03,630 With the commands we've shown you so far, you can only look at files and 2 00:00:03,630 --> 00:00:06,510 directories that already exist on the system. 3 00:00:06,510 --> 00:00:09,380 Now we're going to show you commands that will let you to move, copy, 4 00:00:09,380 --> 00:00:12,370 and delete those files and directories. 5 00:00:12,370 --> 00:00:17,030 Let me make sure I'm in my workspace directory, cd ~/workspace. 6 00:00:18,660 --> 00:00:23,750 First step is the CP command which lets you copy files and directories. 7 00:00:23,750 --> 00:00:27,300 If we list the files in this directory, we'll see bird.txt file. 8 00:00:28,510 --> 00:00:30,320 Suppose I want another bird. 9 00:00:30,320 --> 00:00:33,362 I run the cp command and I give it two arguments, 10 00:00:33,362 --> 00:00:37,789 the name of the file I wanna copy and the name of file I wanna copy it to. 11 00:00:37,789 --> 00:00:41,436 cp bird.txt pigeon.txt. 12 00:00:41,436 --> 00:00:45,728 If I run the ls command again we'll see both the original bird.txt file and 13 00:00:45,728 --> 00:00:47,420 the new pigeon.txt file. 14 00:00:48,440 --> 00:00:51,013 And if I print the contents of pigeon.txt, 15 00:00:51,013 --> 00:00:53,873 we'll see that those have been copied over too. 16 00:00:53,873 --> 00:00:55,360 cp is an important command. 17 00:00:55,360 --> 00:00:57,680 It's one of those commands you'll be using a lot. 18 00:00:57,680 --> 00:01:01,720 That's why its name is abbreviated so you can type it more quickly. 19 00:01:01,720 --> 00:01:04,740 You can use cp to copy files into other directories too. 20 00:01:04,740 --> 00:01:09,486 I can copy bird.txt into the mall directory by giving the directory name as 21 00:01:09,486 --> 00:01:11,230 the second argument to cp. 22 00:01:12,460 --> 00:01:17,116 Now let me change into the mall directory and list its contents, and 23 00:01:17,116 --> 00:01:21,045 you'll see a bird.txt file in this directory as well. 24 00:01:21,045 --> 00:01:24,180 You can also copy files to the parent directory. 25 00:01:24,180 --> 00:01:28,261 Let me change back to the workspace directory cd.. , and now I'll 26 00:01:28,261 --> 00:01:33,005 copy the bird.txt file again specifying the parent directory as the target. 27 00:01:33,005 --> 00:01:37,209 cp bird.txt.. , if I changed to the parent directory and 28 00:01:37,209 --> 00:01:41,760 list its contents, you'll see another bird.txt file there. 29 00:01:43,170 --> 00:01:45,641 You can use cp to copy directories too. 30 00:01:45,641 --> 00:01:48,431 Let me change back to the workspace directory. 31 00:01:52,247 --> 00:01:56,051 Suppose I wanna make a copy of the offices directory, but 32 00:01:56,051 --> 00:01:59,309 I can't just type cp offices/ more_offices. 33 00:02:00,510 --> 00:02:05,800 Normally if you ask cp to copy a directory it will skip it, 34 00:02:05,800 --> 00:02:13,201 but if I add the -r option to cp, it will work, cp -r office/ more_offices. 35 00:02:16,633 --> 00:02:20,580 You can see there's a more_offices directory here now. 36 00:02:20,580 --> 00:02:25,930 The -r options stands for recursive as in copy recursively. 37 00:02:25,930 --> 00:02:31,040 To do something recursively means to do it in a recurring or repeating fashion. 38 00:02:31,040 --> 00:02:34,850 In this case it means that not only will the offices directory be copied, 39 00:02:34,850 --> 00:02:38,630 its contents and all of the contents of its sub directories will be copied too. 40 00:02:39,720 --> 00:02:44,766 Let me list the contents of the more_offices directory, ls more_offices. 41 00:02:47,288 --> 00:02:50,835 You can see its subdirectories have been copied over too. 42 00:02:50,835 --> 00:02:52,880 Any files will get copied over as well. 43 00:02:54,050 --> 00:02:57,530 If I list the contents of the more_offices/web_agency/mcgavren 44 00:02:57,530 --> 00:03:01,890 directory, you'll see a copy of the script file we saw earlier in the course. 45 00:03:03,150 --> 00:03:05,240 So that's how the cp command works. 46 00:03:05,240 --> 00:03:08,680 Now what if you wanna change a file's name without copying it? 47 00:03:08,680 --> 00:03:13,012 In that case, you'd use the mv command which stands for move. 48 00:03:13,012 --> 00:03:21,370 I can move the bird.txt file to sparrow.txt with mv bird.txt sparrow.txt. 49 00:03:21,370 --> 00:03:25,425 You can see there's no longer a file under the name bird.txt but 50 00:03:25,425 --> 00:03:27,765 there is a file named sparrow.txt. 51 00:03:27,765 --> 00:03:32,729 If you specify a directory as a target, you can move a file into that directory. 52 00:03:32,729 --> 00:03:35,570 Let's say we wanna move the hotdog cart to the mall. 53 00:03:35,570 --> 00:03:38,693 We'd run mv cart.txt mall/. 54 00:03:38,693 --> 00:03:40,830 Again, the trailing slash is optional. 55 00:03:42,240 --> 00:03:45,650 If I change to the mall directory and list its files, 56 00:03:45,650 --> 00:03:49,050 you can see that the cart.txt file has been moved there. 57 00:03:49,050 --> 00:03:52,244 And if I change back to the workspace directory and list files, 58 00:03:52,244 --> 00:03:55,509 you can see that the cart.txt file is gone from this directory. 59 00:03:55,509 --> 00:04:00,840 You can move multiple files into a single directory by giving multiple file names. 60 00:04:00,840 --> 00:04:04,758 For example, I can move both the pigeon.txt and 61 00:04:04,758 --> 00:04:11,674 sparrow.txt files into the mall directory with mv pigeon.txt sparrow.txt mall/. 62 00:04:11,674 --> 00:04:14,900 If I change into the mall directory, and list its contents, 63 00:04:14,900 --> 00:04:20,200 you can see that both the pigeon.txt and sparrow.txt files have been moved here. 64 00:04:20,200 --> 00:04:25,120 The move command is one of many commands where wild card expansion comes in handy. 65 00:04:25,120 --> 00:04:28,840 Suppose I wanna move all these text files back to the parent directory. 66 00:04:28,840 --> 00:04:35,990 I could use the wild card *.txt to find all of them, mv *.txt .., will take 67 00:04:35,990 --> 00:04:40,450 all of the .txt files in this directory and move them to the parent directory. 68 00:04:41,550 --> 00:04:45,738 If I list the files here you can see they've all been moved out of this 69 00:04:45,738 --> 00:04:46,559 directory. 70 00:04:46,559 --> 00:04:48,557 And if I change to the parent directory and 71 00:04:48,557 --> 00:04:52,160 list the files you can see they've all been moved here. 72 00:04:52,160 --> 00:04:55,447 Woops, it looks like I also moved the mall map to this directory. 73 00:04:55,447 --> 00:05:00,390 Let me move that back to the mall directory, mv map.txt mall. 74 00:05:03,243 --> 00:05:05,953 This workspace directory is getting a little crowded, 75 00:05:05,953 --> 00:05:08,000 let's remove some of these files. 76 00:05:08,000 --> 00:05:12,356 We do this with the rm command, which stands for remove. 77 00:05:12,356 --> 00:05:16,062 Before we use this command, let me give you a word of warning, 78 00:05:16,062 --> 00:05:18,780 there is no undo for removing files. 79 00:05:18,780 --> 00:05:23,442 The files don't go to a trash folder or anything like that, they're simply gone. 80 00:05:23,442 --> 00:05:26,574 And on Unix-like systems, their data is usually scrubbed 81 00:05:26,574 --> 00:05:32,150 from the disk immediately, meaning there's no such thing as a file recovery program. 82 00:05:32,150 --> 00:05:36,856 So when using the rm command make sure you're removing the correct files. 83 00:05:36,856 --> 00:05:42,710 Let's try removing the bird.txt file, rm bird.txt. 84 00:05:42,710 --> 00:05:46,720 If I list the directory and contents again you can see the bird.txt file is gone. 85 00:05:47,920 --> 00:05:50,698 The rm command can also remove directories. 86 00:05:50,698 --> 00:05:54,860 Let's try deleting this more offices directory we copied. 87 00:05:54,860 --> 00:05:56,629 Just like the what the cp command, 88 00:05:56,629 --> 00:05:59,502 the RM command won't work on directories ordinarily. 89 00:06:02,060 --> 00:06:07,146 But just like the cp command, the rm command has a -r option that causes it to 90 00:06:07,146 --> 00:06:12,650 recursively remove a directory, all its sub-directories and all their files. 91 00:06:12,650 --> 00:06:16,094 If I list files again, you can see more_offices directory is gone now, 92 00:06:16,094 --> 00:06:19,590 along with all the directories and files it contained. 93 00:06:19,590 --> 00:06:25,370 One last command, you can use the mkdir command to make directories. 94 00:06:25,370 --> 00:06:28,565 I can make a park directory with mkdir park. 95 00:06:30,778 --> 00:06:33,820 You can see there's a new park directory here now. 96 00:06:33,820 --> 00:06:36,978 I can change into the new directory, make new sub directories, 97 00:06:36,978 --> 00:06:39,158 anything I can do with any other directory. 98 00:06:40,997 --> 00:06:44,797 If you pass the -p option to make directory, it will make parent directories 99 00:06:44,797 --> 00:06:48,210 for the directory you wanna create if they don't exist. 100 00:06:48,210 --> 00:06:52,440 For example, let's say I want a playground directory inside my park directory, and 101 00:06:52,440 --> 00:06:54,680 a toys directory inside that. 102 00:06:54,680 --> 00:07:00,708 I could run make directory -p park/playground/toys. 103 00:07:00,708 --> 00:07:04,185 The park directory already exists, so that's unchanged. 104 00:07:04,185 --> 00:07:07,981 But there was no playground directory inside the park directory, so 105 00:07:07,981 --> 00:07:09,625 that's been created for us. 106 00:07:11,165 --> 00:07:15,500 And inside the playground directory, a toys directory has been created. 107 00:07:15,500 --> 00:07:19,380 We're now free to fill these playground and toys directories with files or 108 00:07:19,380 --> 00:07:20,530 whatever else we want.