Join us and get access to thousands of tutorials and a community of expert Pythonistas.
This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.
Copying Files - Linux Terminal
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.
00:13
Let’s name it hello/. 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.
00:34
And with this one, let’s say we had the hello_terminal, and then I want to copy this file. So then I need two arguments to it, essentially saying where do I want to copy it as well.
00:43 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.
01:51
Perfect. 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.
02:06
So if we started from this, I could add a different_name.py. Okay. Yeah. And this will then give it in different name inside of the directory. Okay.
02:19
So yeah, go ahead. Why not? We don’t have to hold back on creating new Python files. Right. 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.