android adb查找文件目录下,Android ADB中使用find命令

#include #include"unistd.h"

#include"sys/types.h"

#include"fcntl.h"

int findfile(char *filename,char *path){

struct stat statbuf;

struct dirent *dirp;

DIR *dp;

char tmpbuf[100];

char *ptr;

int num;

if(lstat(path,&statbuf) < 0){

fprintf(stderr,"lstat is error %s",strerror(errno));

return 0;

}

if(S_ISDIR(statbuf.st_mode) == 0){//is a dir

return 0;

}

if((dp = opendir(path)) == NULL){

fprintf(stderr,"opendir is error %s \n",strerror(errno));

return 0;

}

ptr = path + strlen(path);

*ptr++ = '/';

*ptr = 0;

while((dirp = readdir(dp)) != NULL){

num = 0;

if(strcmp(dirp->d_name,".") == 0 || strcmp(dirp->d_name,"..") == 0)

continue;

strcpy(ptr,dirp->d_name);

if(strcmp(dirp->d_name,filename) ==0){

printf("the result:%s\n",path);

}

if(findfile(filename,path) != 0)       //使用递归层级查找所有当前目录下以及当前目录下胡目录下存在的同名文件

break;

}

closedir(dp);

return 0;

}

int main(int arg,char **argc)

{

int i=0;

int ret;

//int resend;

char *tmppath,*path;

char *filename;

FILE *fp;

//printf("111111111111111111111\n");

//for(i = 0; i < arg; i++ )

//printf("the %d argc is %s\n",i,argc[i]);

if(arg != 3){

fprintf(stderr,"args lack:%s\n",strerror(errno));

return -1;

}else{

printf("the original path is %s\n",argc[1]);

path = realpath(argc[1],tmppath);

printf("the path: %s\n",path);

filename = argc[2];

printf("to find filename : %s\n",argc[2]);

}

printf("start:\n\n");

ret = findfile(filename,path);

printf("over!\n\n");

exit(ret);

}

程序写完之后,利用交叉编译工具,将find.c编译成android下能运行的可执行程序:

我所用的是交叉编译工具是arm-none-linux-gnueabi-gcc  4.4.3版本的;

配置交叉编译工具环境变量就不多说了:

编译find.c文件成find可执行文件

lei_lei.zhou@bj61019pcu:~/Find$ arm-none-linux-gnueabi-gcc find.c -static -o find

将find文件push到adb中去:

lei_lei.zhou@bj61019pcu:~/Find$ adb push find /system/bin/

(如果出现failed to copy 'find' to '/system/bin//find': Read-only file system错误,进入到adb shell中执行mount -o rw,remount /system将system文件夹变为可读写的文件系统,再执行上一个命令)

find文件push到system中去了,就可以直接用find查找文件了;

注意这个find命令仅仅实现一个简单且常用查找方式方法:

用法:find

例如:

lei_lei.zhou@bj61019pcu:~/Find$ adb shell

root@MyTestPhone:/ # find ./ wipe                        //在当前根目录向下搜索wipe文件,结果在/system/bin下存在

the path: /

to find filename : wipe

start:

the result://system/bin/wipe

over!

至此,find命令移植到android中完成,如有什么问题可直接联系我:

qq:996340566

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值