Unix/Linux contains "find" command for searching files, but I do not know which command in android can be used to search for a file. Please give me an example.
问题:
回答1:
You may not find find
and grep
on all devices, so probably your safe bet is
$ adb shell ls -lR | grep filename_you_want
on Linux/OSX, or
> adb shell ls -lR | find "filename_you_want"
on Windows.
回答2:
As find
and grep
are not installed on devices I use, I am using the following:
adb shell ls -R / >tree.txt
After that I'm able to search in the file tree.txt on my pc using whatever software I like (for example notepad++ or grep).
回答3:
find
doesn't work for me on my device. Doesn't seem to be installed!
However this sort of works for me:
adb shell
(then in shell)
ls -laR | grep filename_you_want
Hope this helps.
回答4:
Here's a tiny script that should work in zsh and bash. It simulates what you might see if you could run find /
on your Android device:
adb shell ls -R / |
while read line
do
line=$(echo $line | tr -d '\r')
if [[ "$line" =~ ^/.*:$ ]]
then
dir=${line%:}
elif [[ "$line" = "opendir failed, Permission denied" ]]
then
echo "find: $dir: Permission denied"
else
if [[ "$dir" = "/" ]]; then dir=""; fi
echo "$dir/$line"
fi
done
Because it lists all the immediate child directories before descending into them, the output is a little out of order (for example /system
is listed right away but /system/media
doesn't show up until much later). Depending on your needs, you could slap | sort -u
at the end of the script, but it should be all right for all your basic grep
ing needs.
回答5:
Some android devices don't include include find
or grep
in $PATH
. However they might include busybox
. (In my experience, most of them can use busybox
). So you might use them as follow:
adb shell
and then
busybox find . "file.txt"
or something like that
Hope it will help.