How To Copy Files From Mac To USB Hard Drive
How To Copy Files From macOS To USB External Hard Drive In Command-Line.
-
Method 1: How To Copy Files From macOS To USB External Hard Drive In Command-Line.
-
Method 2: How to copy files to flash drive using mac terminal
-
Method 3: Mac File Transfer via Single User Mode / Command Line
-
Master the macOS command line: How to navigate files and folders in Terminal
Method 1
- Open a terminal and run the command
cp -R Documents /usb
. - The
-R
parameter will copy all the subdirectories under theDocuments
directory to the USB external hard drive. - But above command may raise an error message such as
usb/Pics: No such file or directory
. - This is because the USB external hard drive is mounted under
/Volumes
folder, so you should add the/Volumes
directory before USB disk name when you run the cp command.cp -R Documents /Volumes/usb-name
Method 2
How to copy files to flash drive using mac terminal
Question:
Hi, so I’ve been having trouble copying files to a external drive and someone suggested that I try using the terminal to see does that work. For example, if i have a folder on the desktop name “old iTunes” and I want to copy it to a flash drive call “sony samsung” would the command be cp ~/Desktop/old iTunes ~/Volume/sony samsung
thanks
Answer:
The UNIX (command-line) cp(1) command neither protects extended attributes, or copies recursively, by default. If that “old iTunes” is a folder, then the following will copy the folder and its cotents to ~/Volume/”sony samsung.”
cp -pr ~/Desktop/”old iTunes” /Volume/”sony samsung/old iTunes”
Otherwise you will get an error message that “old iTunes” is a directory (not copied). If you do not specify “old iTunes” as the target directory, all of the files in the source “old iTunes” will be splattered all over the “sony samsung” destination.
A command that will preserve extended attributes and do the same thing as above is the ditto(1) command:
ditto ~/Desktop/”old iTunes” /Volume/”sony samsung/old iTunes”
Method 3
Mac File Transfer via Single User Mode / Command Line
- Start in Single User Mode by holding down Command-S when starting the Mac.
- Commands can also be typed via Terminal app when OS X is running.
See also: https://support.apple.com/en-us/HT201573
More tips: http://www.tekrevue.com/tip/mac-startup-options/
Terminal Command Workflow
- Type
diskutil list
to view available drives - Type
diskutil mount /dev/disk1s2
(Disk 1, Partition Scheme 2 – may be different on your Mac) to gain read/write access on that disk. - Type
cd /Volumes
to switch current folder to Volumes where Mac OS lists all mounted drives. - Type
ls
to list contents of Volumes folder. - Type
mkdir
to create a new folder (on the USB drive) - The
cp -a
command copies files/folders from one path to another.
Walkthrough
Start in Single-User Mode by holding Command-S as mentioned above You type -> diskutil list
/dev/disk0
(Physical Disk #1: Macintosh HD)
TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *121.3 GB disk0
1: EFI 209.7 MB disk0s1
2: Apple_HFS Macintosh HD 120.5 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
/dev/disk1
(Physical Disk #2: PIZZA_PIZZA_256GB)
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *256.0 GB disk1
1: EFI 209.7 MB disk1s1
2: Apple_HFS PIZZA_PIZZA_256GB 255.7 GB disk1s
You type -> diskutil mount /dev/disk1s2
Volume PIZZA_PIZZA_256GB on disk1 mounted
You type -> cd /Volumes
/Volumes 13:05:47
You type -> ls
Macintosh HD PIZZA_PIZZA_256GB Recovery Disk Assistant
You type -> cd /Volumes/PIZZA_PIZZA_256GB
You type -> mkdir RecoveredFiles
You type -> cd RecoveredFiles
You type -> cp -a ~/Photos Photos
/Volumes/PIZZA_PIZZA_256GB/RecoveredFiles 13:07:20
Which should copy the entire Mac Photos folder to /Volumes/PIZZA_PIZZA_256GB/RecoveredFiles/Photos
- An empty line after running the
cp
command indicates success - Copy folder and contained files together using
cp -a /Source/FolderName /Destination/FolderName
- Copy single files without the -a using
cp /Source/file.jpg /Destination/file.jpg
- ~/Photos is the same as /Users/alex/Photos
More copying examples
You type -> cp ~/Photos/myphoto.jpg Photos/myphoto.jpg
You type -> cp -a ~/Documents /Volumes/PIZZA_PIZZA_256GB/RecoveredFiles/Documents
You type -> cp -a ~/Desktop /Volumes/PIZZA_PIZZA_256GB/RecoveredFiles/Desktop
Exit Single User Mode
You type -> reboot
Mac will reboot normally
Master the macOS command line: How to navigate files and folders in Terminal
Learn how to perform functions using your Mac’s Terminal commands.
- Delete file: rm -Rf /Volumes/Machintosh HD – Data/Users/…YOURID…/Desktop/filename.pdf
- Delete folder: rm -Rf /Volumes/Machintosh HD – Data/Users/…YOURID…/Desktop/TESTFOLDERFORDELETE
- Look sizes: df – H
- Look inside to folder: ls /Volumes/Machintosh HD – Data/Users/…YOURID…/Desktop/
If you’ve been using a Mac for any length of time, you know that it’s more than just a pretty point-and-click, window-and-icon interface. Beneath the surface of the operating system is an entire world that you can access only from the command line. Terminal (in your /Applications/Utilities folder) is the default gateway to that command line on a Mac. With it, instead of pointing and clicking, you type your commands and your Mac does your bidding.
Why would you want to do that? For almost all of your computing needs, the regular graphical user interface is enough. But the command line can be handy when it comes to troubleshooting your Mac, to turn on “hidden” settings, and other advanced chores. It’s a good idea for anyone who isn’t an utter beginner to be familiar with it.
If you aren’t already familiar with your Mac’s command-line interface. First up: How to navigate the file system from the command-line prompt.
The prompt
By default, when you open Terminal, the first thing you’ll see is something like this:
Last login: Fri Jun 25 10:37:06 on ttys000
romansempire@Mac-Pro-8 ~ %
Here’s what you’re seeing:
- The first line shows the last time you logged into your Mac via the command line; that’s the current time, when you’re using Terminal.
- The second line is the prompt, and while it can change from system to system depending on configuration, by default it contains several bits of information:
- In the prompt above romansempire is the user name.
- Mac-Pro-8 is the name of the Mac (same as the Computer Name in the Sharing pane of System Preferences).
- The ~ shows where you are in the file system of the Mac. ~ is a shortcut that means the current user’s Home folder. (In the Finder, that’s the folder with your user name and the house icon.)
- The % is a character that the shell (the default interface that Terminal uses) displays to indicate that it’s ready to accept a command.
How to see what’s in a folder
When you first get to the command line, you’re in your home folder. While you’re there—or when you’re in any folder (directory in Unix-speak)—you might want to know what’s in it. To do that you use the ls
(or list) command. Type ls
and press the Return key, and you’ll see the folders (and/or files) in the current directory.
The output of the plain ls
command is pretty sparse; it shows you the names of files and folders contained in the current directory (including some familiar ones such as Movies, Music, Pictures, and so on). Fortunately, you can add a number of optional switches to the ls
command that allow you to see more information. For example, type ls -l
(that’s a lower-case L), then press Return. You’ll see something like this:
Don’t worry too much about what all that means right now—we’re just getting our feet wet. The point is that ls
can provide additional information about files and folders, depending on the options you specify. In this case, that additional information includes the name of the user who owns each item in the directory. (That ownership is part of the Unix system’s file-permissions regime.) The romansempire staff
next to most of those items above means that each one is owned by the user romansempire, who is in the group staff. The other understandable bit of information next to each file and folder is the date and time each one was last modified.
One other handy option: You can view invisible files—ones that the Finder doesn’t normally show you—by typing ls -a
. (These hidden files all have dots (.) in front of their names.)
How to access other folders/directories
When you’re in the Finder and you want to move to another folder, you find that folder and double-click it. From the command line, you use the cd
(or change directory) command instead. So let’s say you’re in your Home folder and want to peek inside the Downloads folder. To do that, you’d type cd Downloads
. (Remember to always type a space after any command that has an additional argument, such as the name of a directory in the previous example.) Once you’ve done that, ls
will show you the contents of your Downloads folder.
Here are a couple of quick tricks for moving around in your Mac’s file system.
- If you type
cd
and press the Return key—with no directory specified—you’ll go back to your Home folder. (You can also typecd ~
to go there.) - If you type
cd /
, you’ll go to the root level of your startup disk. - If you type
cd ..
(that’s two periods), you’ll go to the directory above the one you’re currently in. So if you’re in your home folder, and typecd ..
, you’ll go to your Mac’s /Users folder. - And if you type
cd -
(hyphen) you’ll go back to the directory you were in before the last time you issued thecd
command.