Skip to content

Instantly share code, notes, and snippets.

@niraj-shah
Last active August 7, 2025 08:57
Show Gist options
  • Save niraj-shah/6ce7f04fa318728e771f7289f98d9a7c to your computer and use it in GitHub Desktop.
Save niraj-shah/6ce7f04fa318728e771f7289f98d9a7c to your computer and use it in GitHub Desktop.
Shell script to copy only new files using adb
# path to folder on the device
PHONE_PATH=/storage/self/primary/DCIM/Camera/
# path to copy files to
LOCAL_PATH=~/Camera/
# get list of files from the phone folder
adb shell ls -l $PHONE_PATH > file_list.txt
# filter only jpg and mp4 files
grep ".[jpg|mp4]" file_list.txt | awk '{print $NF}' > files_to_pull.txt
# to copy all files, change line 11 to:
# awk '{print $NF}' < file_list.txt > files_to_pull.txt
# copy each file
while IFS= read -r file_path; do
if [ -f "$LOCAL_PATH/$file_path" ]; then
echo "$file_path already exists"
else
adb pull -a "$PHONE_PATH"/"$file_path" "$LOCAL_PATH"
fi
done < files_to_pull.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment