How can I access multiple user spaces from adb? I am running KitKat on a tablet with two users: primary (owner) and secondary. I need to access a file generated by an app of the secondary user.

When I plug the tablet into my (Ubuntu) desktop via USB, it mounts as a media device (MTP), and shows me the base folder for the currently active user. [1] But the file I want is elsewhere on the system, so I connected from the command line via adb shell instead.

Connecting via ADB gives me access to deeper folders (/mnt /proc etc) but I couldn't find the file where I expected it [2], so I looked in /sdcard anyway. To my surprise I recognised the contents as the base folder of the owner account, even though the currently active user is the secondary user.

This also tells me that, if I ever need to, I won't be able to access the base folder for the secondary user via adb shell.

How can I access the tablet from adb shell as the secondary user, rather than the primary (owner) user? (Being able to access the secondary user's files is good enough.)

[1] I'm not sure what the proper term here is. I mean the folder with Android, Download and Pictures, specific to a particular user.

[2] FWIW I am exporting an OPML file from Flym. Flym reports that the OPML export is generated at /storage/emulated/10/Flym_123456789.opml but I can only get as far as /storage/emulated - there is no subfolder called 10, only legacy which is the same as /sdcard (the primary/owner's base folder, not the secondary user's base folder).
The legacy/ locations are always pointing to the data of the currently active user. Let me first point to a few related questions/answers explicitly dealing with those multi-user storage issues for some background:


Why did /sdcard/ turn into /sdcard/0/ with 4.2?
Confusing internal memory folder structure


So to find the files of the secondary user:


list the sub-directories of /data/media and /storage/emulated
restrict your search to sub-directories whose names are simply "numbers"
the 0 candidates belong to the owner, higher numbers are of secondary users
external storage is something different: /sdcard/0 points to the internal sdcard, while /sdcard/1 should be the external (if available). Similarly for storage attached via OTG


Remember you might need to be root to access data of a user other than the one currently active on the device.

Also see:


Android Folder Hierarchy
our tag-wikis for file-system and files