Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I have two android phones, one rooted the other not. When I run following code without asking for root permission on the two phones,

system("echo \"abc\" > /data/a.txt\n");

the rooted phone returns me error-2 (512); the normal phone returns error-1 (256, permission denied). So my question is, what makes this difference.

share|improve this question
BTW: We do have an Android site, but since you asked here, I'm assuming you want to look at this from the Linux level. – derobert Apr 12 '13 at 21:05
up vote 1 down vote accepted

At least on my desktop Linux system, errno 2 is ENOENT, i.e., no such file or directory. You can find out with the errno command (though you probably don't have that on the phone).

That could mean you don't have a /data on that phone (which would be odd). My rooted phone (Galaxy Nexus, running stock Jelly Jean 4.2.2) gives permission denied when I try that in a shell (not in a C program, as you appear to be doing)

I suggest ls -ld /data to start, and maybe also which echo to see if something is different there. Or possibly you don't have a shell; does system("true") work?

share|improve this answer
Thank you Derobert. Both phones have /data for sure. So ideally, being a normal user, when executing the same commands on both phones, there should be no difference, is this correct? Even if one phone is rooted. – brewphone Apr 12 '13 at 22:17
Rooting alone shouldn't make a difference there. (Rooting just installs su and superuser.apk/supersu.apk/etc.) – derobert Apr 14 '13 at 2:36

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.