Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now, I would like to talk about how to copy them. Let's take a look. First of all, we'll do ls -la. Notice that I'm inside my unix_files directory now, which is inside my user root. At the end of the last movie we moved everything into this folder. So you can see I have got all of my unix_files just in this folder. Now, I'll start by doing cat new_file.txt. It's just a very simple text file. Let's copy that. We use cp to copy and we start by saying copy these source.
Our source for this is going to be file.txt. Again, we can provide a full path to that source. It doesn't have to be something that's in this current directory. It can be an absolute path or a relative path. And then the destination, the target. And again, absolute or relative path. In this case, we are going to call it newer_file.txt. It did it. Say ls -la,. We can now see the newer file there and cat newer_file and we see that it copied the content as well. So it's that easy.
It really is just using the cp command to do a copy. The options that we can pass in for copy are the same as they were for move. n is for no overwriting, f is for force overwriting, i is for interactive -- ask me before deciding whether to overwrite or not and v is for verbose, just to give you a little more information about what it's trying to do. And also like move, force overwriting is the default. Let's try that. So I just created this newer_file.txt. Now let's try copying short_file.txt and we'll also put it at newer_file.txt.
So I am basically saying copy short_file and its target should be newer_file.txt. It did it. It didn't object at all and if we say now cat newer_file and see what's in it. You can see it has that short_file text in it. The same thing as short_file, not the same thing as newer_file. So it replaced it destructively. So we would want to use n for don't replace or i for interactive to ask me before we actually do it. Again, when we get to the aliases chapter, we'll talk about how we can change that default all the time.
And the directories work pretty much the same way with one important change. I'll just clear this. So cp test1, that's the directory that's in the folder where I am now. Let's just call it test1_copy. It's a directory so it was not copied. It does that just to make sure that you know, hey, this has a whole lot of stuff. If I make a copy of it, I may be here for a while. That may be copying up lots of stuff, taking a lot of hard drive space. Make sure that really want copy it directly. To do that, we do cp -R for recursive copy.
Keep copying down the line recursively for every single folder that's inside this directory and that will allow us to copy test1 to test1_copy. Take a look, there it is. So that -R option, is going to come a lot. R is really the option. Generally lowercase r works as well. So, you don't have to worry too much about remembering which one it is, but technically it should be the capital R. That's really all there is to being able to copy files.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98181 Viewers
61 Video lessons · 85482 Viewers
71 Video lessons · 69439 Viewers
56 Video lessons · 101790 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.