I want to check if a certain directory (e.g. /data/textdata/) exists on the AVD using adb shell.

I'm following prolink007's answer on SO, except this line:

DIR_RESULT=$(adb shell ls /data/ | tr -d '\015'|grep '^textdata$')

but it goes always into the then branch if the directory exist or not. I've also looked for the adb shell manual without results.

Any suggestion?

2 Answers 2


I tried this on an avd and it works for me:

ls /data/textdata > /dev/null 2>&1 && echo "exists" || echo "not exists"

Please try this:

DIR_RESULT=$(adb shell if [ -d  "/data/textdata" ]; then echo "exists"; else echo "not exists"; fi; );
  • does not work. it says "exist.sh: command substitution: line 4: syntax error near unexpected token then' exist.sh: command substitution: line 4: then echo "exists"; else echo "not exists"; fi; '". I think is how the command is structured: if statement should not be there (in my opinion)
    – idell
    Commented Dec 5, 2013 at 15:13
  • the command of prolink007 now works: i was wrong in the command copy.
    – idell
    Commented Dec 5, 2013 at 15:26
  • I found a solution which works for me. See my second answer. Commented Dec 5, 2013 at 15:29

You must log in to answer this question.