To transfer photos from your Android device to your Mac using the command line, follow these steps:
-
Install
adb
(Android Debug Bridge):- If you haven't already installed
adb
, you can do so using Homebrew:brew install android-platform-tools
- If you haven't already installed
-
Enable Developer Options and USB Debugging on Android:
- Go to
Settings > About phone
, then tapBuild number
seven times to enable Developer Options. - Go to
Settings > Developer options
, and enableUSB debugging
.
- Go to
-
Connect Your Android Device to Mac:
- Use a USB cable to connect your Android device to your Mac.
-
Verify the Connection:
- In your terminal, run:
adb devices
- You should see your device listed. If prompted on your Android device, allow USB debugging.
- In your terminal, run:
If device is offline then run below command and tap allow on mobile:
adb kill-server
adb start-server
To view folders:
adb shell
cd /sdcard
ls
Photos and images are typically stored in the following directories:
- Camera photos: /sdcard/DCIM/Camera/
- Screenshots: /sdcard/Pictures/Screenshots/
- WhatsApp images: /sdcard/WhatsApp/Media/WhatsApp Images/
- Downloads: /sdcard/Download/
- Transfer Photos:
- Navigate to your
DCIM
folder (where your camera photos are usually stored) on your Android device and copy them to your Mac:adb pull /sdcard/DCIM/Camera/ ~/Desktop/AndroidPhotos/
- This command copies all photos from the
Camera
folder on your Android device to a folder namedAndroidPhotos
on your Desktop.
- Navigate to your
To copy all images from phone run this:
adb pull /sdcard/Pictures ~/Desktop/AndroidImages
adb pull /sdcard/DCIM ~/Desktop/AndroidImages/DCIM
adb pull /sdcard/WhatsApp/Media/WhatsApp\ Images ~/Desktop/AndroidImages/WhatsApp
adb pull /sdcard/Download ~/Desktop/AndroidImages/Downloads
- Safely Disconnect:
- After the transfer is complete, you can safely disconnect your Android device from your Mac.
This method provides a command-line alternative to using the Android File Transfer tool.
cd ~/Desktop
touch backup_android_photos.sh
vi backup_android_photos.sh
script to copy all automatic:
#!/bin/bash
# Ensure adb is installed
if ! command -v adb &> /dev/null
then
echo "adb (Android Debug Bridge) is not installed. Install it with 'brew install android-platform-tools'."
exit 1
fi
# Get the current date and time
TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")
BACKUP_FOLDER=~/Desktop/MobileBackup_$TIMESTAMP
# Create the backup folder
mkdir -p "$BACKUP_FOLDER"
# Start adb server
adb kill-server
adb start-server
# Check if the device is connected
if ! adb devices | grep -q "device$"; then
echo "No Android device connected or authorized. Ensure USB debugging is enabled and authorize the connection."
exit 1
fi
# Define folders to back up
FOLDERS=(
"/sdcard/DCIM"
"/sdcard/Pictures"
"/sdcard/WhatsApp/Media/WhatsApp Images"
"/sdcard/Download"
)
echo "Starting backup process..."
# Copy folders
for FOLDER in "${FOLDERS[@]}"; do
echo "Backing up $FOLDER..."
adb pull "$FOLDER" "$BACKUP_FOLDER"
done
echo "Backup completed. Files saved to: $BACKUP_FOLDER"
# Safely disconnect adb
adb kill-server
Make executable file
chmod +x backup_android_photos.sh
Run the file:
./backup_android_photos.sh
#!/bin/bash
# Ensure adb is installed
if ! command -v adb &> /dev/null
then
echo "adb (Android Debug Bridge) is not installed. Install it with 'brew install android-platform-tools'."
exit 1
fi
# Define the backup folder
BACKUP_FOLDER=~/Desktop/MobileBackup_Latest
# Create the backup folder if it doesn't exist
if [ ! -d "$BACKUP_FOLDER" ]; then
mkdir -p "$BACKUP_FOLDER"
echo "Backup folder created: $BACKUP_FOLDER"
else
echo "Backup folder exists: $BACKUP_FOLDER"
fi
# Start adb server
adb kill-server
adb start-server
# Check if the device is connected
if ! adb devices | grep -q "device$"; then
echo "No Android device connected or authorized. Ensure USB debugging is enabled and authorize the connection."
exit 1
fi
# Define folders to back up
FOLDERS=(
"/sdcard/DCIM"
"/sdcard/Pictures"
"/sdcard/WhatsApp/Media/WhatsApp Images"
"/sdcard/Download"
)
echo "Starting backup process..."
# Copy folders with skipping of existing files
for FOLDER in "${FOLDERS[@]}"; do
echo "Backing up $FOLDER..."
# Check if the folder exists on the device
if adb shell "[ -d $FOLDER ]"; then
# Copy files incrementally
adb shell "find $FOLDER -type f" | while read -r FILE; do
# Extract file name from full path
FILE_NAME=$(basename "$FILE")
DEST_FILE="$BACKUP_FOLDER/${FILE#$FOLDER/}"
# Check if the file already exists
if [ ! -f "$DEST_FILE" ]; then
# Create destination directory if not exists
mkdir -p "$(dirname "$DEST_FILE")"
# Pull the file
echo "Copying: $FILE"
adb pull "$FILE" "$DEST_FILE" || echo "Failed to copy $FILE"
else
echo "Skipping existing file: $FILE_NAME"
fi
done
else
echo "Folder $FOLDER does not exist on the device. Skipping."
fi
done
echo "Backup completed. Files saved to: $BACKUP_FOLDER"
# Safely disconnect adb
adb kill-server