How to search a file with adb.exe?

2019-02-02 21:19发布

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.

标签: android adb
5条回答
趁早两清
2楼-- · 2019-02-02 21:49

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.

查看更多
叼着烟拽天下
3楼-- · 2019-02-02 21:57

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.

查看更多
forever°为你锁心
4楼-- · 2019-02-02 21:59

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.

查看更多
一纸荒年 Trace。
5楼-- · 2019-02-02 22:06

As findand 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).

查看更多
疯言疯语
6楼-- · 2019-02-02 22:11

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 greping needs.

查看更多
登录 后发表回答