Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Copying Files

00:00 The next task I’m having for you—maybe we can clear it out again, and we start fresh again. So the next task I have for you is to copy the hello_terminal.py file into a subdirectory. Let’s name it hello/.

00:15 It should still be present in your current directory but also copied into this hello/ directory. Yes.

00:23 So as you may have seen in some of the others we did here, these commands tend to have very short names. So copy is shortened down to just being cp. And with this one, let’s say we had the hello_terminal, and then I want to copy this file.

00:39 So then I need two arguments to it, essentially saying where do I want to copy it as well. So if I just run this, you can see that it’s giving me an error saying that it also needs a destination file. Now you’re actually asking me to copy it into a directory, and that means that we need to have a directory to copy it into.

00:57 So before doing the copying, I’ll create that directory. So this is the same as we did earlier. We do the mkdir, and now we can see if I do ls, we have this one—it has a slightly different color because it’s a directory—and then we have our two files over here.

01:16 Once I have this directory, I can then copy the hello_terminal, and then I also want to say where do I want to copy it, and if I just say hello like this,

01:27 at least it’s not yelling at us. So that’s promising. And as long as it’s copying into a directory, it’ll just take the same filename and put that one into the directory.

01:38 So we can go with the cd (change directory), which you also saw earlier, and have a look inside of here. And we can see that we have just now the hello_terminal file that was copied from the one that’s in the directory above. Perfect.

01:52 So if you would have decided to rename the file in there, you could also have written hello/ then hello_newname.py and rename it in this go or— Yes, exactly. So if we started from this, I could add a different_name.py.

02:13 Okay. Yeah. And this will then give it in different name inside of the directory. Okay. So yeah, go ahead. Why not? We don’t have to hold back on creating new Python files. Right.

02:27 Nice. Okay, wonderful. So now we have two files in there, a different_name.py one and the hello_terminal one.

Become a Member to join the conversation.