Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
Unix for Mac OS X Users unlocks the powerful capabilities of Unix that underlie Mac OS X, teaching how to use command-line syntax to perform common tasks such as file management, data entry, and text manipulation. The course teaches Unix from the ground up, starting with the basics of the command line and graduating to powerful, advanced tools like grep, sed, and xargs. The course shows how to enter commands in Terminal to create, move, copy, and delete files and folders; change file ownership and permissions; view and stop command and application processes; find and edit data within files; and use command-line shortcuts to speed up workflow. Exercise files accompany the course.
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.
Find answers to the most frequently asked questions about Unix for Mac OS X Users.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
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.