3

I'm trying to copy all of my pictures from my Samsung Galaxy S9+ to my laptop (running Linux Mint). I can transfer a few files at a time no problem, but I have amassed 1000's of files in my pictures folder.

When attempting to copy the folder across using the file manager, the operation stalls and then fails every time. I would prefer to do it via the terminal, but since Samsung phones use mtp to transfer files, I have no idea what commands to use.

1

1 Answer 1

3

MTP is crap for that task – OK for a few files in "small folders", but stalling for folders with many files in, or copying many files, or trying things in parallel.

As you use Linux, ADB would be a great alternative. I use that with adbfs-rootless, which allows mounting the device locally on your computer and works like a charm (I'm using it for years, so I can confirm it works at least up to Oreo).

First, to get ADB running, you can check with How do I get my device detected by ADB on Linux?. ADB binaries are shipped in the repositories of many distributions by a name like android-tools-adb so you can easily install them; alternatively take a look at Is there a minimal installation of ADB? for an even smaller footprint.

Installation of adbfs is quite straight-forward if you have the essential build tools already installed on your system: according to the readme, next to build-essential you'll need libfuse-dev and pkg-config available on your system. The git package is only needed if you want to clone the Github repository (alternatively, you can simply download the code as ZIP). cd to the directory you've cloned/unpacked the code to, and run make. When that's done, copy the adbfs binary to your path (e.g. into /usr/local/bin or ~/bin if you've set that up), so you don't need to specify the full path with each call – and you are ready to use it.

Finally, create a mount-point (an empty directory where your device's file system shall appear, say mnt in your home directory), and mount it with adbfs ~/mnt – et voila, your copy party can begin; from the terminal or graphically is up to you. When done, use fusermount -u ~/mnt to unmount your device again.

As a little bonus for you: should you sometimes have multiple devices attached at the same time, you'll need to set the ANDROID_SERIAL environment variable to tell adbfs which device to connect to. Here's a little script making that easier for you:

        case "$(adb devices|grep -v "devices"|grep -v -e '^[[:space:]]*$'|wc -l)" in
          0) echo "Nothing to mount (no device attached)" ;;
          1) export ANDROID_SERIAL=$(adb devices|grep -v "devices"|grep -v -e '^[[:space:]]*$'|awk '{print $1'})
             adbfs /mnt/droid
             ;;
          *) devices=''
             tmpfile=$(tempfile)
             adb devices -l|grep -v "devices"|grep -v -e '^[[:space:]]*$' > $tmpfile
             while IFS='\n' read i
             do
               test="$(echo $i | awk '{print $2}')"
               if [ "$test" = "device" ]; then
                 devices="$devices $(echo $i | awk '{print $1}')"
                 devices="$devices \"$(echo $i | awk '{print $5}')\""
               fi
             done < "$tmpfile"
             rm -f -- "$tmpfile"
             serial=$(whiptail --clear --menu 'Multiple devices found, make your choice:' 0 0 0 $devices 3>&1 1>&2 2>&3)
             export ANDROID_SERIAL=$serial
             adbfs /mnt/droid
        esac

If you wonder about the indention: it's a snippet out of my Midnight-Commander (mc) menu. You can insert it there, preceding it by

= t d
+f ^mnt$
m       Mount Droid

So whenever your mount point is highlighted by the cursor, pressing F2 will make that menu item available and you can easily mount your device. For unmounting, here's the second menu item:

+f ^mnt$
u       uMount Droid
        fusermount -u /mnt/droid

^mnt$ is the name of the mount-point you've created – so if you used a different name, you need to adjust this as well.

Enjoy!

2
  • Thank you! Mounting the phone is a much better solution.
    – Reece
    Commented Aug 28, 2019 at 15:19
  • 1
    Definitely. Makes you completely free to chose the copy software you prefer – be it command-line cp/rsync or a graphical file manager. You could even go a step further and integrate that with a udev rule – so whenever that device is attached, its storage would be mounted automatically. I haven't done that as I'm unsure how to handle the umount then, which must be done before unplug and thus would be hard to automate ;)
    – Izzy
    Commented Aug 28, 2019 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .