简体   繁体   中英

How to write your own ls command and make it run on Rooted Android Terminal?

I want to write my own ls command,so that i could safely parse it.

I have written the following code in c. But how to make this .c file run in terminal emulator for android.? Do i need to simply put it in /system/bin directory?

#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>

int main(int argc, char* argv[])
{
    DIR *mydir;
struct dirent *myfile;
struct stat mystat;

char buf[512];
mydir = opendir(argv[1]);
while((myfile = readdir(mydir)) != NULL)
{
    sprintf(buf, "%s/%s", argv[1], myfile->d_name);
    stat(buf, &mystat);
    printf("%zu",mystat.st_size);
    printf(" %s\n", myfile->d_name);
}
closedir(mydir);
}

No. Why would you think that would work? C is a compiled language, not interpreted. You'd need to compile it for ARM linux first. (I'm assuming ARM, as most devices are- your mileage may vary, and you may need to compile for the correct version of ARM).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM