Web Niraj
  • Facebook
  • Flickr
  • Github
  • Linkedin
  • Twitter
  • YouTube
Online portfolio, code examples and developer blog
  • About
  • Contact
  • Portfolio
  • WordPress
Search the site...
  • Home
  • Blog
  • Copying New Files from Android to Mac Using ADB

Copying New Files from Android to Mac Using ADB

0

Sometimes, I like to back up my photos and videos from my Android device to my Mac manually. Sure, I have Google Photos backup photos to the cloud, but having a local backup is also useful. I use ADB to copy files from my Pixel 8 Pro to my Mac. However, ADB doesn’t have a easy way to backup only newer files, so I had to find my own solution.

In the past, I’ve used the adb pull command to easily backup photos, but this method can take ages when you have hundreds of files on the device. The following command does not ignore existing files on the destination:

adb pull -p -a /storage/self/primary/DCIM/Camera/ ~/Camera

So, I came up with a solution using a shell script and the same command above. The script assumes you already have ADB setup and configured on your system.

The script (found below) first gets a list of files I want to copy from the device folder and writes this to a file (file_list.txt). I then filter the files in the temp file to only give me the filetypes (or even prefix) that I want and write the list of files to another file (files_to_pull.txt, this file now contains only the full filenames that need to be copied, and not the other information from the ls -l command).

Then, we loop through each line in the file and check if the file already exists in the destination folder. If the file does not exist, adb pull is used to copy the file from the device to the destination.

You can easily change the device path and destination by editing Lines 2 and 5 in the code above. If you need to filter other filetypes or a different patten entirely, you can edit line 11. I wouldn’t edit anything else unless you understand the code.

ADB, Android, Command Line

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

StackExchange / StackOverflow

profile for Niraj Shah on Stack Exchange, a network of free, community-driven Q&A sites

Support Me

PSN Profile

Tags

ACL Amazon Amazon Web Services Android Android 4.4 KitKat Android 5.0 Lollipop Apache Backup Bug Command Line Cordova cPanel / WHM Facebook Facebook Graph API Facebook PHP SDK 4.0 Facebook Social Plugins Fan Page Firewall Flash Geolocation Google Nexus 5 Hacking HTML5 iOS IP Abuse JavaScript jQuery Laravel 5 Linux NodeJS Parse PDF PHP Plugin Portfolio PS4 Review Security Server SSH SSL Sysadmin Tutorial WordPress WordPress Plugins
© 2011-2025 Niraj Shah
  • Blog
  • Portfolio
  • WordPress
  • About Me
  • Contact Me
  • Privacy Policy
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Privacy Policy