1 00:00:06,639 --> 00:00:09,980 While working with Linux, you will commonly need to copy files as well. 2 00:00:10,509 --> 00:00:12,609 The CP command is helping you to do so. 3 00:00:13,529 --> 00:00:14,349 So how does it work? 4 00:00:14,939 --> 00:00:19,929 Well, you use cpdir sumfile to sumdir to copy a file. 5 00:00:20,949 --> 00:00:25,000 Now if the destination file is sumdir, then you probably want to 6 00:00:25,000 --> 00:00:29,050 copy to copy it to a directory with the name sumdir. 7 00:00:30,710 --> 00:00:36,490 But if you don't have sumdir currently existing, it will create some file to a file with the name sumdir. 8 00:00:37,350 --> 00:00:42,909 Confusing? Yeah. And if you don't want that to happen, then you might better have the 9 00:00:42,909 --> 00:00:48,469 command fill if sumdir doesn't exist and do so by putting a slash behind somdir. 10 00:00:50,609 --> 00:00:55,924 Now when you are using CP you you might use CP A. You remember the A 11 00:00:55,924 --> 00:01:01,239 option. In ls it includes hidden files as well. In CP it is doing the same. 12 00:01:03,280 --> 00:01:06,299 So CP A copies all files including hidden. 13 00:01:06,920 --> 00:01:12,469 But you need to use the dot star wealth card to make it complete. 14 00:01:13,090 --> 00:01:16,819 And that means that your command is going to look like CP A tilde to tmp. 15 00:01:20,200 --> 00:01:25,780 Now personally I wouldn't copy hidden files that way. You are probably better off using the TAR 16 00:01:25,780 --> 00:01:31,359 utility which we will cover later. It's a much better solution to create archives of complete directories. 17 00:01:33,040 --> 00:01:36,830 Also convenient is CP uppercase r 18 00:01:36,830 --> 00:01:40,620 which will copy recursively including subdirectories. 19 00:01:41,569 --> 00:01:42,150 Let me show you. 20 00:01:43,959 --> 00:01:47,719 Okay, first I'm going to use CP etchosts to dot. 21 00:01:48,379 --> 00:01:53,739 Hey, what is dot? Dot is current directory. So it copies the file hosts into the current directory. 22 00:01:54,799 --> 00:01:57,959 And LS is showing that we now have a file with the name hosts. 23 00:01:59,219 --> 00:02:06,189 Next I'm going to use CP uppercase r tmp to dot which is doing what? Well, 24 00:02:06,189 --> 00:02:13,159 it's giving a couple of access messages on directories that I don't have permissions to. 25 00:02:14,039 --> 00:02:18,219 But it will also copy the TMP directory and into the current directory. 26 00:02:19,259 --> 00:02:24,280 Now let me copy CP etc hosts to newdir. 27 00:02:25,560 --> 00:02:30,490 What do I want to do? Well, I want to copy the file etchost to newdir. And what do you think of that? 28 00:02:30,990 --> 00:02:35,514 Well, LS L is showing that it has created a file with the name newdir 29 00:02:35,514 --> 00:02:40,039 and it has the exact same size as the host file that we copied previously. 30 00:02:40,740 --> 00:02:45,810 So why is that? Well, based on the name newdir, my shell cannot know that that it's actually 31 00:02:45,810 --> 00:02:50,879 into a directory that I want to copy the file and that is why it created the file. 32 00:02:52,080 --> 00:02:58,766 So if you really want it to be copied to a directory, then you would use 33 00:02:58,766 --> 00:03:05,453 CP et host mydear put a slash behind the name of the directory and in case 34 00:03:05,453 --> 00:03:12,139 the directory doesn't exist, then it will give you an error message, not a directory. 35 00:03:13,050 --> 00:03:16,030 And that is exactly what we wanted here. 36 00:03:17,129 --> 00:03:20,819 So the solution mkdir to create a directory and then 37 00:03:20,819 --> 00:03:24,509 you can try it again and then it would work. 38 00:03:25,250 --> 00:03:29,759 So this is about all that you should know about cp. Let's move on to the next video.