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

2 Answers 2


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 or from a terminal emulator.

  • 2
    Good Teamwork :) +1
    – Flow
    Commented Oct 3, 2011 at 20:19
  • 2
    Very good! Thanks! Note, though, that if you may need to escape $ depending on your shell. example: adb shell echo \$EXTERNAL_STORAGE
    – notlesh
    Commented Oct 3, 2011 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.
    – notlesh
    Commented Oct 3, 2011 at 22:16
  • @stephelton That's disappointing. Which one's incorrect? $EXTERNAL_STORAGE is correct for me, /mnt/sdcard/external_sd/. Commented Oct 12, 2011 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/Environment.java 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.

  • 2
    I figured out the adb command using this info, +1. Commented Oct 3, 2011 at 20:07

You must log in to answer this question.

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