I plugged my Kit-kat android phone up to my Ubuntu 14.04 computer and I enter the terminal and I want to be able to access files on my phone like the media and music folders through the terminal... is this possible?
-
Depends on the vendor. Some (Samsung) make it harder, others easier. – mikewhatever Mar 13 '15 at 19:21
-
I have the note 4 @mikewhatever – cmehmen Mar 13 '15 at 19:25
-
2...and what happens when you connect it? Does Ubuntu see it? What's the output of `dmesg`? Is there an option is the phone settings to allow connecting to USB? – mikewhatever Mar 13 '15 at 20:15
2 Answers
Android devices usually uses the Media Transfer Protocol (MTP) when connecting via the USB. This protocol works differently than the traditional USB.
Simply put, this is a way to ensure that the phone does not share too much data with the computer. The computer makes a query, and the phone answers it. The phone may decide to share the file or ignore the query. Similarly, when the computer deletes a file, the phone has the ability to decide whether to actually delete the file or not.
Okay, enough introduction. To access a device connected via MTP, you need the information about it's #Bus and #Dev. To do so, you can run the following command.
usb-devices
This will provide you with a list of connected usb-devices. You need to find your device from this list. It can be a bit tiring, so you can search for the device with the available Manufacturer option. Simply use the following command.
usb-devices | grep "Manufacturer=OnePlus" -B 3
This will provide you with 4 lines of information, where the firs line is as follows.
T: Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 13 Spd=480 MxCh= 0
As you can see here, the associated Bus is 02, and Dev is 13.
Now change your directory to /run/user/1000/gvfs/ and see the list of folders there.
/run/user/1000/gvfs/
ls
You will find the associated MTP device with the #Bus and #Dev in the list. For example, mine was mtp:host=%5Busb%3A002%2C013%5D. Now simply change your directory using the following command.
cd mtp\:host\=%5Busb%3A002%2C013%5D/
Voila! You are inside the file storage!
- 391
- 3
- 5
-
3
-
2
-
9What if there is nothing in `/run/user/1000/gvfs/`. My `ls` doesn't show anything. – Nikhil Wagh Oct 22 '18 at 10:17
-
3same here. the folder is empty. i set my phone to 'file transfer' mode in case that matters. – roy May 16 '20 at 18:37
-
Note the following command. `usb-devices | grep "Manufacturer=OnePlus" -B 3` I used OnePlus because my phone was manufactured by OnePlus. You will have to put your manufacturer name In it's place. I think this should fix the error. – Muntasir Wahed Oct 13 '20 at 05:47
-
1If the folder /run/user/1000/gvfs/ s empty, install gvfs-fuse with "sudo apt-get install gvfs-fuse" and reboot your system. Probably will work after that. =) – R. W. Prado Oct 01 '21 at 05:25
You can find the mount point under the $XDG_RUNTIME_DIR/gvfs directory. The main directory may be something like mtp:host=… with some escaped characters and USB vendor/product IDs, but you should be able to access your files from in there in a terminal.
- 40,344
- 5
- 56
- 98
-
I'm uncertain how to follow your instructions. What directory is `$XDG_RUNTIME_DIR/gvfs` in? I can't find it anywhere. Is it hidden? – Sarah Szabo Jan 30 '18 at 00:51
-
2The `$XDG_RUNTIME_DIR` defaults to `/run/user/$UID/` I think. There is a `gvfs` sub-directory within it. – dobey Jan 30 '18 at 03:02
-
I've found the `gvfs directory, but I don't see anything in it using the `ls` command. – Sarah Szabo Jan 30 '18 at 21:40
-
OK. This was working when I answered the question in 2015 on 14.04. Maybe something changed/broke in newer Ubuntu in relation to this? – dobey Jan 30 '18 at 23:05
-
Possibly, should I re-ask the question, bu with it related to modern systems? – Sarah Szabo Jan 31 '18 at 02:20
-
Maybe should file a bug report on https://bugs.launchpad.net/ubuntu/+source/gvfs – dobey Jan 31 '18 at 02:40