Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use find command in adb shell

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?

like image 338
kosbou Avatar asked Oct 26 '12 08:10

kosbou


People also ask

How do I search for files in adb shell?

I used adb shell "ls -lR [ top-level-dir ]/[ varying number of */ ]/[ known part of filename ]> to find a glob pattern that matches the file, then started putting subdirs in the pattern - if the glob doesn't match, try the next subdir. It looked something like this: /lib/libSmth*. so , /lib/*/libSmth*.

Which adb command is used to find connected devices?

Syntax used to access ADB instances from commands line: Adb [-d – An adb command when a single USB device is connected Adb [-e – An adb command when only single emulator is running Adb devices--- This will print all the list of emulator / devices attached.


Video Answer


4 Answers

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

like image 72
Misha Avatar answered Oct 13 '22 10:10

Misha


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

like image 44
RichardUSTC Avatar answered Oct 13 '22 10:10

RichardUSTC


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

like image 36
jox Avatar answered Oct 13 '22 10:10

jox


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'"
like image 1
Alex P. Avatar answered Oct 13 '22 10:10

Alex P.