296

I have an Android phone that connects with my computer via MTP. This works fine; I can see and transfer files with Nautilus. However, I often want to use the terminal to move large numbers of files, and I cannot seem to find the device anywhere in the filesystem tree. Nautilus reports the location as mtp://[usb:003,007]/, but it's not under /media or /mnt.

Does anyone know where it is?

bessman
  • 7,425

14 Answers14

229

As you have already found out, the mountpoints are in /run/user/$USER/gvfs/ (or /var/run/user/$UID/gvfs) and are named after the protocol, connection type and address they use. Which makes things more difficult, because the connection address may change every time you replug the device, even if it is the same port. If you have the same device twice it gets even worse.

You can use lsusb to display all connected USB devices from terminal:

$ lsusb | grep Google   # Note: This is a Nexus 4, change accordingly
Bus 002 Device 025: ID 18d1:4ee2 Google Inc.

As you have noticed Nautilus also gives this information via tool tip. You will find the encoded form of e.g. mtp://[usb:002,025] in /run/user/$USER/gvfs (or /var/run/user/$UID/gvfs) as mtp:host=%5Busb%3A002%2C025%5D


Asker's edit: This seems to require a newer version of libmtp and/or gvfs than is available per default in 13.04. Run sudo add-apt-repository ppa:langdalepl/gvfs-mtp and update before doing anything else.


Edit: PPA not needed anymore in saucy/13.10 and newer, filenames are listed in terminal as they are in Nautilus.

Edit 2016-01-11: I removed the script that was previously included in this answer due to lack of time for maintenance and improvements. You can still find it in the revision history.

Pablo Bianchi
  • 15,657
LiveWireBT
  • 28,763
  • Thank you for your answer. Unfortunately, it doesn't work because the actual folder names (e.g. /DCIM/Camera/) are only visible in Nautilus, not the terminal. Thus, $Path/DCIM/Camera is not accessible with rsync. – bessman Sep 08 '13 at 14:16
  • 2
    The path is just an example and is different for Android phones. The phone must also be unlocked via lock screen to allow access to the data. – LiveWireBT Sep 08 '13 at 15:37
  • The path /DCIM/Camera/ exists on my phone, but in the terminal it is called /2404/2407/. That's the problem. If I cd into /2404/2407/ and run nautilus ., then /DCIM/Camera/ is opened. The phone is unlocked, otherwise I wouldn't be able to access it via Nautilus, right? – bessman Sep 08 '13 at 17:37
  • That's odd, there should be no difference between Terminal and Nautilus. I don't know details of how MTP works on a deeper level and where your issue is rooted. You could try switching to PTP protocol and see if you get proper file names in this mode. My desktop runs on 12.10 with GVFS-MTP PPA and my phone runs CM 10.2 nightlies. – LiveWireBT Sep 09 '13 at 14:22
  • I am (or was) on vanilla 13.04. Phone runs CM 10.2 nightly. I added ppa:langdalepl/gvfs-mtp to my sources and now it works as expected! Thank you, if you edit your answer to say to run sudo add-apt-repository ppa:langdalepl/gvfs-mtp first I'll accept it. – bessman Sep 10 '13 at 14:54
  • Mine was located in: /home/$user/.gvfs/mtp/ – Justin Feb 04 '14 at 23:08
  • I can find the files under /run/user/, but I can't even cp files, since cp: cannot open <filename> for reading: Operation not supported Still I can copy the files by file manager. – jarno Oct 19 '14 at 21:09
  • 9
    Note that in order for all of this to work, you need to have the gvfs-fuse package installed. Not all versions/flavors of Ubuntu have it by default (e.g. Ubuntu MATE 14.10 doesn't). Without it the MTP device won't get mounted as a local path and will only be usable by applications that support gvfs URIs. – user149408 Nov 07 '14 at 15:24
  • thx but unfortunately some commands like unzip or tar wont work to extract files there, that's a weird filesystem.. :( – Aquarius Power Nov 22 '14 at 18:36
  • You should never use a variable named Path - it might override your $PATH variable if you are a bit off. :) – David Oct 26 '15 at 20:08
  • 4
    I found the gvfs/ directory eventually. However instead of $USER, the path on this PC is: /run/user/1000/gvfs/mtp:host=%5Busb%3A003%2C003%5D -- For others I suggest you just poke about, if you don't find it right away. – will Mar 03 '17 at 21:25
  • I was sudo'd as root when trying to get into /run/user//gvfs. It wasn't letting me in, gave me permission errors. Which is just pain odd, if you ask me. Anyway, if you use the user with the am id as the directory, you can get in just fine. Just leaving this comment for anyone else confused like me. :) – David R. Nov 04 '18 at 18:27
  • 3
    There is no /run/user/$USER/gvfs/directory in 18.04 or 19.10, but there is /run/user/<uid>/gvfs and /var/run/user/<uid>/gvfs. – jarno Feb 06 '20 at 07:25
  • @jarno: Not for me. If there is something it is inaccessible. But mtp:// still works fine, regardless if the mount point is present or not. But only for certain graphical clients, but not for things like the terminal. – Tino Jun 17 '21 at 09:52
  • 4
    I have an MTP device connected, but neither /run/user/$USER/gvfs/ nor /var/run/user/$UID/gvfs have anything in them for me, on Ubuntu 22. – Raleigh L. Oct 19 '22 at 04:40
120

My Nexus device's memory can be accessed at:

/run/user/$UID/gvfs/mtp*

So if your $UID is 1000, you may find it by either doing

$ cd /run/user/$UID/gvfs/mtp*

or (for the exact location in an example assuming your UID is 1000),

$ cd /run/user/1000/gvfs/mtp\:host=%5Busb%3A001%2C006%5D/
Evan Carroll
  • 7,526
Babken Vardanyan
  • 1,251
  • 1
  • 8
  • 6
  • 6
    This should be the accepted answer since it doesn't not require installing any additional software. Thanks a lot user2529583! – NH. Jan 18 '17 at 00:45
  • Any idea if the mtp* filename can be renamed for use in Wine applications? Naive mv gives me mv: cannot move 'mtp:host=%5Busb%3A001%2C065%5D' to 'mtp': No such file or directory (note that the filename is tab-completed) – Mark Jeronimus Nov 10 '17 at 12:32
  • @Mark any character is a valid filename in linux. Look if there is a way rename it without mv. – Babken Vardanyan Nov 10 '17 at 12:35
  • Awesome. It works perfectly fine and saved me a lot of "trying out" on Raspbian Wheezy and Jessie – Zimano Dec 18 '17 at 10:15
  • 4
    Ubuntu 16.04 and Honor 9 Lite. After connecting phone /run/user/1000/gvfs folder is empty. – LRDPRDX Sep 15 '18 at 06:35
  • Same basic path to Sony Cyber-shot in KDE Krusader (PTP access via USB cable): /var/run/user/1000/gvfs/gphoto2:host=Sony_Sony_PTP/ – Victoria Stuart Mar 29 '19 at 20:40
  • This solved the problem for me. Thank you. This should be the accepted answer. – Maxim Jul 04 '19 at 12:59
  • Oddly, this doesn't work in Kubuntu 20.04 – cipricus May 18 '21 at 10:37
29

MTP mounted device usually can be found in : /run/user/1000/gvfs/


for eg if your Nautilus address bar shows mtp://[usb:001,006]/, then you can access by:

/run/user/1000/gvfs/mtp\:host=%5Busb%3A001%2C006%5D/

now on terminal you can copy files or folders:

  • cd into folder -> cd /run/user/1000/gvfs/mtp\:host=%5Busb%3A001%2C006%5D/
  • then copy required folders to current directory -> cp -r ~/videos/ .
suhailvs
  • 1,373
  • 1
  • 13
  • 21
  • 3
    It works exactly like you say. But when I make 'ls -a' it is empty. – cvr Sep 20 '17 at 16:12
  • 2
    Ubuntu 20.04: /run/user/$UID/gvfs/ is inaccessible, as mtp:// devices are handled outside of the filesystem these days, making them unreachable for (commandline) virus scanners etc. Well done, Canonical! – Tino Jun 17 '21 at 09:50
21

I got an LG2 phone and I am running Xubuntu 15.10.

This is how I mounted the device to mnt directory in under my user.

  1. First make sure you have the following packages installed in your system.

    sudo apt-get install jmtpfs mtp-tools
    
  2. Connect your phone as MTP device and type the following command in your terminal.

    mtp-detect
    
  3. Uncomment user_allow_other in file /etc/fuse.conf.

  4. Create a directory mnt in your home directory.

    mkdir mnt
    
  5. Mount the device.

    jmtpfs ~/mnt
    
  6. Thats it. Now your device is mounted under the mnt directory created in step 4.

Note: There may be some steps that are unnecessary. But following the above steps worked for me.

Reference: https://wiki.archlinux.org/index.php/MTP

Iron Heart
  • 221
  • 2
  • 2
  • 2
    On Ubuntu 22 I get this error when I try to run mpt-detect: libusb_claim_interface() reports device is busy, likely in use by GVFS or KDE MTP device handling alreadyLIBMTP PANIC: Unable to initialize device – Raleigh L. Jul 11 '23 at 03:30
  • 1
    On Ubuntu 20.04 the similar error appears when running mpt-detect: error returned by libusb_claim_interface() = -6LIBMTP PANIC: Unable to initialize device Unable to open raw device 0 – Anton Samokat Sep 19 '23 at 07:47
13

This is working with:

  • Linux Mint 17.3
  • Samsung Galaxy S5

Try this:

  1. apt-get install mtpfs
  2. apt-get install mtp-tools
    • # yes could be one line (this is optional)
  3. sudo mkdir -p /media/mtp/phone
  4. sudo chmod 775 /media/mtp/phone
    • # Personally I'd restrict permissions to NO-eXecute
    • # At this point I'm not sure what is enough to mount.
  5. Unplug the phone micro-USB and plug-in, then...
  6. sudo mtpfs -o allow_other /media/mtp/phone
  7. ls -lt /media/mtp/phone

Output:

 total 0
 drwxrwxrwx 2 will will 0 Jan  1  1970 Card
 drwxrwxrwx 2 will will 0 Jan  1  1970 Phone
 drwxrwxrwx 2 will will 0 Jan  1  1970 Playlists
  1. ls -lt /media/mtp/phone/Card

Output:

 total 0
 drwxrwxrwx 2 will will 0 Jan  1  1970 Android
 drwxrwxrwx 2 will will 0 Jan  1  1970 DCIM
 drwxrwxrwx 2 will will 0 Jan  1  1970 LOST.DIR
 drwxrwxrwx 2 will will 0 Jan  1  1970 Music

Listing access to the SD-card on my Android phone. "Playlists" is a virtual directory called "/Playlists" which contains your playlists as .m3u files. (per man mtpfs)

That seems to do the trick. Useful commands to remember ...

  • sudo mtpfs -h ... lists the device's options. This seems to only work before you have mounted the device. So check first-off, perhaps.
  • mtp-detect ... shows lots of stuff about the device (part of mtp-tools).

Also, I think you need the phone/device "on", open the screen-saver if you have one so the device can connect.

I noticed that my USB-s mount as:

  • /media/will/usbdrive

So it might make more sense to mount under your username instead of the "mtp" stub. Also, review the post: "Mounting Your MTP Androids SD-card on Ubuntu", it has a few useful suggestions and extras.

References

I took my lead from these two posts:

Pablo Bianchi
  • 15,657
will
  • 348
  • 1
    Hi although this works, I still find the MTP is too slow and often it is as if my Linux PC has locked. I support the further comments about using FTP. I did some digging and recommend the sshelper app. It is very useful, open sourced, and mature. Will work with Windows, Linux and Mac -- Or anything that supports SSH. Easy to use too. Give it a go. – will Sep 21 '17 at 07:54
11

I don't know exactly to traverse to MTP location via terminal. However, I found out that we can right click on the Internal storage / SD card and choose option "Open in Terminal". Doing so the location is directly opened in Terminal.

screenshot

Pablo Bianchi
  • 15,657
  • 3
    A real screenshot (of the internal framebuffer) would be so much better than a photo of the screen (with an external camera). – David Foerster Apr 19 '18 at 23:19
  • 1
    After finding that path, we can add the invariable part to the file manager left panel as a bookmark, for example /run/user/1000/gvfs. – cipricus Apr 10 '20 at 14:42
  • 2
    Ubuntu 20.04: no "Open in Terminal" for MTP devices anymore. Thank you Canonical! – Tino Jun 17 '21 at 09:40
11

Type mount. That will list every active filesystem.

waltinator
  • 36,399
  • 25
    No, the device does not show up in the output. – LiveWireBT Sep 06 '13 at 22:54
  • 1
    Hmm. That sort of worked. I found it under /run/user/myusername/gvfs/. However, all the foldernames are just numbers instead of the actual names that I see in Nautilus. As such, it doesn't really solve my problem because I still can't easily use the terminal to move files to the device. – bessman Sep 07 '13 at 07:21
  • 1
    When Nautilus has the MTP device open, use the commands lsof -c nautilus | less to list all file files Nautilus has open. – waltinator Feb 03 '14 at 19:13
  • 1
    That solved it for me :) – marlar Apr 10 '15 at 10:28
6

This is not a direct answer to the problem, but a solution nonetheless.

After experiencing inconsistency's with USB connectivity, I bypassed the .gvfs and USB system all together.

I installed a simple ftp server on the android and voila! Connect to server (either ftp with login or without, depending on how you choose) from Nautilus/nemo/thunar and away you go.

Syncronisation of folders is handled through OwnCloud and/or BitTorrentSync.

And the FTP over wireless is way quicker than the USB connection was.

6

MTP is a protocol, much like FTP or SSH. It fetches files when the user asks for it. Thus there is no mounted file system on the computer.

Use mtpfs in order to make it appear like a mounted file system.

mtpfs <a_folder_to_mount>

No need to specify the device. If you have only one device connected, then there is no ambiguity. I have not tested it with multiple devices connected to my computer.

3

enter image description here

After accessing the correct path as said HERE and other answers, a good idea is to add the invariable path (for example /run/user/1000/gvfs) as a bookmark to the file manager left panel. When phone is disconnected, that folder will be empty.

I have noticed that there is a difference between the options available for a file accessed in this way and those available for the same file when accessed the "normal" way, by the mtp:// path (clicking "mtp" or the device name/numbers on the left panel): when accessed by /run/user/.../gvfs the file has in context menu ("Open with") all the expected options; these options are limited (reduced to default/vanilla ones) when the file is accessed by mtp://. Also, some programs (e.g. MKVToolNix) cannot access a file by the mtp:// path, but they can by the other one. This aspect may become important is some scenarios, like for example when one needs to create/download a file on the phone, process it through a computer program (e.g. MKVToolNix) and output it on an external device.

cipricus
  • 3,444
  • 2
  • 34
  • 85
  • 1
    Ubuntu 20.04: Does not work anymore. Opening the device with mtp:// works fine, but there is nothing mapped into the filesystem, so it's hidden from rgrep or similar tools like (commandline) virus scanners. Well done, Canonical! – Tino Jun 17 '21 at 09:46
  • @Tino - the situation is worse in KDE, where files on android cannot be read without being first copied to cache: https://askubuntu.com/q/1339104/925128 – cipricus Jun 17 '21 at 14:32
2

In the last few days, my MTP connection was deadly slow again. I'm still on 18.04 and can't upgrade to 20.04 just yet (I'm working on devices that require 18.04).

The first I encountered the problem, I was able to find a file with parenthesis and deleted that file and things went back to normal. Until now. I really need to have fast access to my pictures as I use that feature for my work, so I looked further... and found out that there is a fix available as expected in the launchpad bug report.

Here is a copy of the specific entry that fixed it for me:

I have just tried installing libmtp-1.1.17-2 on 18.04 from here: https://launchpad.net/ubuntu/+source/libmtp/1.1.17-2/+build/18694144 files:

  • libmtp-common_1.1.17-2_all.deb
  • libmtp-runtime_1.1.17-2_amd64.deb
  • libmtp9_1.1.17-2_amd64.deb
    (disconnect phone and after installation log out and log in back to the system or reboot for new libraries to be loaded)
    Now listing files is quick and I can actually transfer files.

The following are the commands I ran:

wget https://launchpad.net/ubuntu/+source/libmtp/1.1.17-2/+build/18694144/+files/libmtp-common_1.1.17-2_all.deb
wget https://launchpad.net/ubuntu/+source/libmtp/1.1.17-2/+build/18694144/+files/libmtp-runtime_1.1.17-2_amd64.deb
wget https://launchpad.net/ubuntu/+source/libmtp/1.1.17-2/+build/18694144/+files/libmtp9_1.1.17-2_amd64.deb
sudo dpkg -i libmtp9_1.1.17-2_amd64.deb libmtp-common_1.1.17-2_all.deb libmtp-runtime_1.1.17-2_amd64.deb

In my case, I had to reboot anyway, so I rebooted. But as the poster on launchpad said, you should at least log out and back in from your X11 session. I then took a few pictures, reconnected the phone as usual and it was instantaneously connected and worked as expected. No pause between the connection and the availability of the gvfs file system.

Note: The files are for Focal Fossa (20.04) but you can safely install them on Bionic Beaver (18.04) and it works. It would be great if they would make an upgrade to fix the problem in 18.04, though. Oh well...

Alexis Wilke
  • 2,707
2

I am able to manage files on a MTP connected Android device using gvfs-* commands (e.g. gvfs-cp, gvfs-move, ...) which are also mentioned in the following Wikipedia article: GVfs.

I wrote a simple CLI utility for file synchronization to/from an Android device: https://github.com/DusanMadar/PySyncDroid

1

You might consider that your OS is simply hiding automount processes from you, as my Kubuntu 20.10 does. I think that this is the reason for this question to come up so often. To avoid this, read this short thread here:

Disabling USB Automount

The sentence "Maybe excluding the 'plugdev' from your user profile will do it." was the one that helped me in the end! I got myself out of the plugdev group and from then on all problems regarding my phone USB connection were solved.

The best thing is: You can change this whenever you like without disturbing and messing up the system configuration.

  • But do you know what is the mounted location in Kubuntu? (20.04 in may case). The phone is mounted somewhere, isn't it? Only maybe it's not in /run/user/1000/gvfs/, that folder is empty. Did you use deluser <username> plugdev? – cipricus May 18 '21 at 10:04
  • What exactly happens after removing user from that group? What problems did you have and solved? And where/how is the mount point visible after that? – cipricus May 18 '21 at 10:13
  • See here: Dolphin doesn't mount locations, it accesses them via separate KIO processes. This avoids blocking UI applications. – cipricus May 18 '21 at 12:23
0

I don't like go lang, but in my case i found that go-mtpfs utility is a little faster then jmtpfs. It works the same as jmtpfs:

go-mtpfs ~/mount-point-folder
superqwerty
  • 45
  • 1
  • 1
  • 7