Posted by Gary Rosenzweig on 4/24/09.
You can follow Gary on Twitter.
Sometimes the Finder can fail you when you want to copy lots of files, like an entire CD or DVD. Learn how to use the Terminal to copy whole volumes with better error handling and reporting.
Video Transcript (Click to Expand)
Hi, this is Gary with MacMost Now.
On today’s episode, let’s take a look at how you can use the terminal to copy files when the finder fails you.
So recently I got in a situation where I needed to copy the data from all these data DVDs back to a hard drive. I would drag and drop, holding the option key, the DVD to the hard drive, and it commence copying all of the data on the DVD to the hard drive. But then it would hit a file that it had a problem with. Sometimes this was a package file, an older type of install file for Mac OS X. Other times it was very different types of files, and it would come up with an error and simply stop copying. It would stop copying in the middle of a sub-folder of a sub-folder of a folder and I would end up with half of the data over on my drive and I’d have to figure out what wasn’t copied and manually copy each individual folder afterwards. It was very complex. And I really just wanted it to skip these files that it couldn’t copy, and copy everything that it could.
Well, it turns out the finder just couldn’t really do it. But the terminal could do it easily. Let me show you how.
So, you can find terminal in your applications folder. When you run it you get a screen kind of like this, although the default is for a white background with black text. I’m going to go ahead and type “df” which will list all the different devices and drives attached. And the key to this is finding out the actual real name as the terminal will see it. And here I can find the DVD that I’ve inserted, which is iPhoto Library – 2003-2005. Here’s the name. It’s /Volume/iPhoto Library. I’m just going to select it and copy it so I can paste it into a command exactly as it appears here.
Now the next thing you want to do is you want to go to the place where you’re going to copy the files to. So, for instance, I’m going to go into my documents folder. So, that would be in “users” and my user name, “documents”. And there I am.
Now to copy, we use the cp command. But the cp command, by itself, will only copy a file. If you have a folder, it won’t look inside the folder. Matter of fact, it’ll complain to you about the folders. So what you want to do is you want to tell it you want to copy folders and folders inside of folders and files inside of that, etc. You want to do that with -r. r for recursive. In other words, look inside of everything and keep looking deeper and deeper, and it’ll copy everything starting with the directory you’re going to specify. The next thing you want to do is you want to tell it to retain all the properties of the files so you want to put a “p” there too, so we have “r” and “p”. Now the next one’s optional. You can do “v” for verbose. That’ll basically give you output of every single file it’s copying, so you can see what’s happening. If you leave that off, it’ll just be quiet unless it encounters an error.
Now we want to put the name of the place we’re copying from. Now we’ve copied before from the df command, the exact file of the volume we want. So we’re just going to put a ” and paste it in there. The reason we need a quote is because there’s spaces in the name, as there typically are in Mac files and folders and DVDs and CDs, etc. If you put a space in a command line in the terminal, it will take this as a separation of parts of the command. You don’t want that. You want to tell it that this is a full name of that volume. So, you want to put a “, paste in that volume name, which includes the spaces that you see, and then close the quote, like that. Now, if we hit return, it will copy this entire volume to the location that we’re at.
Now we’re not done quite yet. We need to show it where to copy to. Now since we’ve already navigated to the directory we’re copying to, we can simply tell it we want it in the current location. We can do that with a dot slash (./), basically saying the same directory. Now when I hit return, we’ll start to see all the items copied in this new location.
While it’s doing that, I can actually go ahead and look in the finder in my documents, and I can see that there’s a folder with the name of that directory, and it’s copying stuff into it. There’s the iPhoto Library, since it’s an iPhoto disk, and look, you can see it adding folders right there as we watch.
Now if you ever make a mistake, or notice it’s copying the wrong thing, you can always hit CONTROL and C (not COMMAND and C), to break running a program in terminal like that. And while you’re in there, you can also look up more information about the cp command. The way to do that is to type “man” for manual, and “cp”, and it will give you all sorts of information and other options, in case you’re interested.
So again, the advantages of this is that it won’t fail if there’s just one file there that it can’t copy. It’ll just give you an error message and keep going. Matter of fact, if you leave out the v for verbose, you’ll see nothing happening unless it runs into an error. So it’s a great way if you’re having trouble, to see exactly which files it didn’t copy and perhaps you can try to do something with those afterwards. That’s a quick look at using cp in terminal to copy files when the finder fails you. Until next time, this is Gary Rosenzweig with MacMost Now.
Hi, this is Gary with MacMost Now.
On today’s episode, let’s take a look at how you can use the terminal to copy files when the finder fails you.
So recently I got in a situation where I needed to copy the data from all these data DVDs back to a hard drive. I would drag and drop, holding the option key, the DVD to the hard drive, and it commence copying all of the data on the DVD to the hard drive. But then it would hit a file that it had a problem with. Sometimes this was a package file, an older type of install file for Mac OS X. Other times it was very different types of files, and it would come up with an error and simply stop copying. It would stop copying in the middle of a sub-folder of a sub-folder of a folder and I would end up with half of the data over on my drive and I’d have to figure out what wasn’t copied and manually copy each individual folder afterwards. It was very complex. And I really just wanted it to skip these files that it couldn’t copy, and copy everything that it could.
Well, it turns out the finder just couldn’t really do it. But the terminal could do it easily. Let me show you how.
So, you can find terminal in your applications folder. When you run it you get a screen kind of like this, although the default is for a white background with black text. I’m going to go ahead and type “df” which will list all the different devices and drives attached. And the key to this is finding out the actual real name as the terminal will see it. And here I can find the DVD that I’ve inserted, which is iPhoto Library – 2003-2005. Here’s the name. It’s /Volume/iPhoto Library. I’m just going to select it and copy it so I can paste it into a command exactly as it appears here.
Now the next thing you want to do is you want to go to the place where you’re going to copy the files to. So, for instance, I’m going to go into my documents folder. So, that would be in “users” and my user name, “documents”. And there I am.
Now to copy, we use the cp command. But the cp command, by itself, will only copy a file. If you have a folder, it won’t look inside the folder. Matter of fact, it’ll complain to you about the folders. So what you want to do is you want to tell it you want to copy folders and folders inside of folders and files inside of that, etc. You want to do that with -r. r for recursive. In other words, look inside of everything and keep looking deeper and deeper, and it’ll copy everything starting with the directory you’re going to specify. The next thing you want to do is you want to tell it to retain all the properties of the files so you want to put a “p” there too, so we have “r” and “p”. Now the next one’s optional. You can do “v” for verbose. That’ll basically give you output of every single file it’s copying, so you can see what’s happening. If you leave that off, it’ll just be quiet unless it encounters an error.
Now we want to put the name of the place we’re copying from. Now we’ve copied before from the df command, the exact file of the volume we want. So we’re just going to put a ” and paste it in there. The reason we need a quote is because there’s spaces in the name, as there typically are in Mac files and folders and DVDs and CDs, etc. If you put a space in a command line in the terminal, it will take this as a separation of parts of the command. You don’t want that. You want to tell it that this is a full name of that volume. So, you want to put a “, paste in that volume name, which includes the spaces that you see, and then close the quote, like that. Now, if we hit return, it will copy this entire volume to the location that we’re at.
Now we’re not done quite yet. We need to show it where to copy to. Now since we’ve already navigated to the directory we’re copying to, we can simply tell it we want it in the current location. We can do that with a dot slash (./), basically saying the same directory. Now when I hit return, we’ll start to see all the items copied in this new location.
While it’s doing that, I can actually go ahead and look in the finder in my documents, and I can see that there’s a folder with the name of that directory, and it’s copying stuff into it. There’s the iPhoto Library, since it’s an iPhoto disk, and look, you can see it adding folders right there as we watch.
Now if you ever make a mistake, or notice it’s copying the wrong thing, you can always hit CONTROL and C (not COMMAND and C), to break running a program in terminal like that. And while you’re in there, you can also look up more information about the cp command. The way to do that is to type “man” for manual, and “cp”, and it will give you all sorts of information and other options, in case you’re interested.
So again, the advantages of this is that it won’t fail if there’s just one file there that it can’t copy. It’ll just give you an error message and keep going. Matter of fact, if you leave out the v for verbose, you’ll see nothing happening unless it runs into an error. So it’s a great way if you’re having trouble, to see exactly which files it didn’t copy and perhaps you can try to do something with those afterwards. That’s a quick look at using cp in terminal to copy files when the finder fails you. Until next time, this is Gary Rosenzweig with MacMost Now.


Thanks for the tip!
To place volumes/folders/files names; Instead of typing it in the terminal, you can open a Finder window, then locate the desired source (or destination), then simply drag-and-drop the object inside the Terminal window. The complete path will be entered automatically by Unix at the cursor position.
Man, you really made my day! I was stuck with my whole itunes library, and no possibility to copy it back to a newly formatted FAT32 external drive. I wish I had found your post earlier. Would have saved me some precious time. You’re first in my bookmarks now!