how to use find command in adb shell

2019-04-26 06:02发布

I want to check if there is a certain file inside a directory in my android device.

I use the following line in my windows batch

adb shell find /mnt/sdcard/koinoxrista -name Bill.txt

I want to do something if the file exists and something else if file does not exist.

How can I do this?

4条回答
倾城 Initia
2楼-- · 2019-04-26 06:08

When you know the exact file name you do not need to use any extra commands like find to look for it. Simply check if it exists using built-in shell facilities:

adb shell "[ -f /mnt/sdcard/koinoxrista/Bill.txt ] && echo 'found'"
查看更多
3楼-- · 2019-04-26 06:09

Find command is not supported in adb shell. This command will also show you hidden files adb shell ls -laR | grep filename

查看更多
走好不送
4楼-- · 2019-04-26 06:27

The find command is supported in Android since version 6.0 (Mashmallow).

This is because it's including Toybox since then.

https://en.wikipedia.org/wiki/Toybox

查看更多
萌系小妹纸
5楼-- · 2019-04-26 06:32

I am afraid that the Android emulator does not provide with the 'find' program.

查看更多
登录 后发表回答