ADB ->文件目录操作

📁 基础目录导航

进入设备环境

bash 复制代码
adb shell                   # 进入设备shell环境
pwd                         # 显示当前目录路径
cd /storage/emulated/0      # 切换到内部存储
cd /                        # 回到根目录
cd ..                       # 返回上级目录

🔍 查看文件列表

bash 复制代码
ls                          # 基本文件列表
ls -l                       # 详细信息(权限、大小、时间)
ls -a                       # 显示所有文件(包括隐藏文件)
ls -la                      # 详细信息 + 隐藏文件(最常用)
ls -lh                      # 详细信息 + 人性化大小显示
ls -lt                      # 按修改时间排序
ls -lS                      # 按文件大小排序

🔍 文件查找操作

bash 复制代码
按文件名查找
adb shell find /storage/emulated/0-name "DCIM"         # 精确匹配名称
adb shell find /storage/emulated/0 -name "*DCIM*"      # 包含DCIM的名称
adb shell find /storage/emulated/0 -name "*.jpg"       # 以.jpg结尾的文件
adb shell find /storage/emulated/0 -name "DCIM*"       # 以DCIM开头的名称
按文件大小查找
adb shell find /storage/emulated/0 -size +10M           # 大于10MB的文件
adb shell find /storage/emulated/0 -size -1M            # 小于1MB的文件
adb shell find /storage/emulated/0 -size +100M          # 大于100MB的文件
按文件类型查找
adb shell find /storage/emulated/0 -type f              # 只查找文件
adb shell find /storage/emulated/0 -type d              # 只查找目录
按修改时间查找
adb shell find /storage/emulated/0 -mtime -1            # 1天内修改的文件
adb shell find /storage/emulated/0 -mtime +7            # 7天前修改的文件

📊 目录大小统计

bash 复制代码
查看目录占用空间
adb shell du -sh /storage/emulated/0        # 内部存储总大小,不显示目录下的文件
存储使用情况
adb shell df -h /storage/emulated/0         # 查看内部存储使用情况,显示目录下的文件

📝 文件内容操作

bash 复制代码
查看文件内容
adb shell cat /storage/emulated/0/config.txt            # 查看完整文件内容
adb shell head -10 /storage/emulated/0/app.log          # 查看文件前10行
adb shell tail -10 /storage/emulated/0/app.log          # 查看文件后10行
adb shell tail -f /storage/emulated/0/app.log           # 实时查看文件末尾

搜索文件内容

bash 复制代码
adb shell grep "error" /storage/emulated/0/app.log      # 搜索包含error的行
adb shell grep -i "ERROR" /storage/emulated/0/app.log   # 忽略大小写搜索
adb shell grep -n "crash" /storage/emulated/0/app.log   # 显示行号
adb shell grep -A 5 "exception" /storage/emulated/0/app.log  # 显示匹配行及后5行

🛠️ 文件管理操作

bash 复制代码
创建目录
adb shell mkdir /storage/emulated/0/test        # 创建单个目录
adb shell mkdir -p /storage/emulated/0/app/logs/crash   # 创建多级目录
删除文件和目录
adb shell rm /storage/emulated/0/temp.txt               # 删除单个文件
adb shell rm -r /storage/emulated/0/temp_folder         # 删除目录
adb shell rm -rf /storage/emulated/0/cache/*            # 清空目录内容
adb shell rm -f /storage/emulated/0/*.tmp               # 强制删除临时文件
复制和移动
adb shell cp /storage/emulated/0/source.txt /storage/emulated/0/backup.txt     # 复制文件
adb shell cp -r /storage/emulated/0/source/ /storage/emulated/0/backup/        # 复制目录
adb shell mv /storage/emulated/0/old.txt /storage/emulated/0/new.txt           # 移动/重命名文件

📱 应用数据操作

bash 复制代码
查看应用信息
adb shell pm path com.example.app           # 查看应用APK路径
adb shell pm list packages | grep example   # 查找应用包名
访问应用私有数据(仅debug应用)
adb shell run-as com.example.app ls -la     # 查看应用目录
adb shell run-as com.example.app ls -la databases/    # 查看数据库目录
adb shell run-as com.example.app ls -la shared_prefs/ # 查看配置文件目录

🎯 核心目录结构

bash 复制代码
Android文件系统
├── /sdcard/                # 内部存储(用户可访问)
│   ├── DCIM/               # 相机照片
│   ├── Download/           # 下载文件
│   ├── Pictures/           # 图片文件
│   └── Android/data/       # 应用公共数据
├── /data/data/             # 应用私有数据(需要权限)
│   └── com.package/
│       ├── databases/      # 数据库文件
│       ├── shared_prefs/   # 配置文件
│       ├── files/          # 应用文件
│       └── cache/          # 缓存文件
├── /system/app/            # 系统应用
└── /data/app/              # 用户安装应用
相关推荐
活宝小娜3 天前
mysql详细安装教程
数据库·mysql·adb
zhangjin11203 天前
adb install和 pm install 的区别是什么?
adb
炼川淬海DB5 天前
数据库开发规范
android·adb·数据库开发
何极光5 天前
MySQL 8.0详细安装教程(附下载地址)
数据库·mysql·adb
sevencheng7985 天前
【ADB】adb命令行常用按键模拟代码
linux·adb·模拟按键,返回键,音量键
QX_hao6 天前
mysqldump-vs-xtrabackup
adb·mysql备份
云计算磊哥@7 天前
运维开发宝典028-MySQL04数据库热备
数据库·adb·运维开发
charlee447 天前
Unity在安卓端如何调试输出信息
android·unity·adb·游戏引擎·真机调试
ai_coder_ai8 天前
如何使用adb实现自动化脚本?
运维·adb·自动化
pigs20188 天前
mysql8.0 access denied for user root localhost account is locked
数据库·adb