Android ADB中使用find命令
来源:互联网 发布:美国加拿大合并 知乎 编辑:程序博客网 时间:2024/05/01 21:09
在adb中经常需要查找一些文件或者是目录,但是很可惜adb所用busybox指令集中并没有包含find命令;
所以在多次觉得不便胡情况下,决定自己用C 语言实现一个find命令的精简版本,仅仅为了查找文件或者目录;
代码如下:
find.c:
#include<stdio.h>
#include<stdlib.h>
#include<dirent.h>
#include<string.h>
#include<sys/stat.h>
#include<errno.h>
#include <time.h>
#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
所以在多次觉得不便胡情况下,决定自己用C 语言实现一个find命令的精简版本,仅仅为了查找文件或者目录;
代码如下:
find.c:
#include<stdio.h>
#include<stdlib.h>
#include<dirent.h>
#include<string.h>
#include<sys/stat.h>
#include<errno.h>
#include <time.h>
#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
上一篇:(原创) Framework中PowerManagerService分析
下一篇:(原创)android Framework中AlarmManagerSerevice分析理解
相关热门文章
- Android之开发环境搭建
- Android自定义View的实现...
- AndroidManifest.xml配置文件...
- Android相对布局+圆角按钮+Sha...
- 查看Android应用包名package和...
- linux dhcp peizhi roc
- 关于Unix文件的软链接
- 求教这个命令什么意思,我是新...
- sed -e "/grep/d" 是什么意思...
- 谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
评论热议
0 0
- Android ADB中使用find命令
- Android中adb命令的使用
- 在Android studio中使用adb命令
- Android中adb命令
- Android使用adb命令
- Android adb命令使用
- Android adb 命令使用
- android adb命令使用
- android adb 命令使用
- adb使用-android adb shell 命令大全
- android中使用adb shell命令kill掉应用程序
- Android中sdcard和adb命令的使用
- android中使用adb shell命令kill掉应用程序
- Android中常用adb命令及Log使用
- android中使用adb shell命令kill掉应用程序
- Android中使用ADB 命令安装和卸载系统程序
- Android开发中常见adb命令的使用
- adb命令查看Android中内存使用情况
- Linux 同步方法剖析--内核原子,自旋锁和互斥锁
- adb shell中设置android系统内部环境变量!
- 面对自己:如何让自己成为真正的程序员
- ReactNative学习二
- HDU-4569 Special equations (数学)
- Android ADB中使用find命令
- Andrid进阶_Ksoap2访问WebService出现错误SoapFault
- static的作用
- iOS开发-UIView之动画效果的实现方法
- IOS把url中含有的中文字符转化为UTF8编码方法
- Java构建工具:Ant vs Maven vs Gradle
- 机器学习基础(三十八) —— 从几率到逻辑斯函数
- 写博客还是有必要的
- 使用NavigationController的一个小技巧
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
全自动清粪机
皮带清粪机
养殖场清粪机
小型清粪机
鸽子自动清粪机
养鸡清粪机
履带式清粪机
履带清粪机
鸡厂清粪机
铲式清粪机
河南清粪机
手动清粪机
羊圈清粪机
全自动清粪机报价
清粪机绳子
输送带式清粪机
养猪清粪机
猪厂清粪机
猪清粪机
猪圈清粪机
自制清粪机
手推式清粪机
自动清粪机公司
带式清粪机价格
鸡棚清粪机
牵引式清粪机
鸡用清粪机
机械清粪机
鹌鹑清粪机
半自动清粪机
清粪机配件
自动清粪机安装
养鸡设备清粪机
养兔清粪机
鸡舍自动清粪机厂家
蛋鸡养殖自动清粪机
清粮机
多功能清粮机
粮食清粮机
大豆清粮机
水稻清粮机价格