Skip to content

Instantly share code, notes, and snippets.

@kwcto
Created October 22, 2015 18:51
Show Gist options
  • Save kwcto/45e0b985071fad655e17 to your computer and use it in GitHub Desktop.
Save kwcto/45e0b985071fad655e17 to your computer and use it in GitHub Desktop.
How to copy files / folders off a Mac from the command line (optionally using Single User Mode)

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

  1. Type diskutil list to view available drives
  2. Type diskutil mount /dev/disk1s2 (Disk 1, Partition Scheme 2 - may be different on your Mac) to gain read/write access on that disk.
  3. Type cd /Volumes to switch current folder to Volumes where Mac OS lists all mounted drives.
  4. Type ls to list contents of Volumes folder.
  5. Type mkdir to create a new folder (on the USB drive)
  6. 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

  1. An empty line after running the cp command indicates success
  2. Copy folder and contained files together using cp -a /Source/FolderName /Destination/FolderName
  3. Copy single files without the -a using cp /Source/file.jpg /Destination/file.jpg
  4. ~/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

@dayfuaim
Copy link

dayfuaim commented Oct 3, 2019

Thank you so much!
It would save me my Mini.

@AngDrew
Copy link

AngDrew commented Apr 13, 2021

thank you! works fine even in 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment