Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way I can use ADB to determine the external storage directory (equivalent of the Android API call Environment.getExternalStorageDirectory())?

share|improve this question
up vote 9 down vote accepted

adb shell echo $EXTERNAL_STORAGE. All credit goes to Flow for leading me to experiment and find this.

Naturally you can use cd $EXTERNAL_STORAGE or whatever else you might need during an adb shell session.

share|improve this answer
Good Teamwork :) +1 – Flow Oct 3 '11 at 20:19
Very good! Thanks! Note, though, that if you may need to escape $ depending on your shell. example: adb shell echo \$EXTERNAL_STORAGE – stephelton Oct 3 '11 at 20:43
Hmm, it turns out that my samsung vibrant gives me a different value for $EXTERNAL_STORAGE than it does Environment.getExternalStorageDirectory(). This isn't the first nasty bug I've found on this phone. – stephelton Oct 3 '11 at 22:16
@stephelton That's disappointing. Which one's incorrect? $EXTERNAL_STORAGE is correct for me, /mnt/sdcard/external_sd/. – Matthew Read Oct 12 '11 at 21:15

I don't think that this is possible. See Matthew's Post

But let's have a lock on how Environment.getExternalStorageDirectory() returns the external storage directory. A quick look in android/os/ shows that all this method does, is returning a static constant File member called EXTERNAL_STORAGE_DIRECTORY. This constant is initialized by

private static final File EXTERNAL_STORAGE_DIRECTORY
        = getDirectory("EXTERNAL_STORAGE", "/sdcard");

which calls getDirectory()

static File getDirectory(String variableName, String defaultPath) {
    String path = System.getenv(variableName);
    return path == null ? new File(defaultPath) : new File(path);

So the external storage directory is nothing else then an java System environment variable (or a predefined default). You could try to follow this trace further. Maybe the external storage directory is just a hard coded path in some configuration file on the filesystem. Or maybe there is a way to read out these environment variables via adb that I don't know.

share|improve this answer
I figured out the adb command using this info, +1. – Matthew Read Oct 3 '11 at 20:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.