For rooted Android devices
You can consider installing BusyBox app by Stephen. Per Play Store, the minimum Android version supported by app is Android 1.6 and it is a well-updated app. In essence, it installs the busybox binary into /system/xbin
and places symlinks in the same directory for all the utilities it has.
What is BusyBox (not the app)?
BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils, etc. The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete environment for any small or embedded system.
Here is the official list of utilities it provides. find
tool can be found there.
A competent alternative to BusyBox is Toybox, which has replaced Toolbox in Marshmallow release.
Toybox combines many common Linux command line utilities together into a single BSD-licensed executable. It's simple, small, fast, and reasonably standards-compliant (POSIX-2008 and LSB 4.1).
Here is the official list of utilities toybox supports. BusyBox, at the moment, appears to support more tools than Toybox.
I do not think an app exists to install Toybox binary, so you may use my answer here for the purpose of its installation. Note that the answer can be used for the installation of both Toybox and BusyBox. Only prerequisite is downloading the binary from official sources.
Official download links:
For non-rooted Android devices
I do not know whether there is a universal approach for all Android versions. That said, for Android 4.0 and up BusyBox Install (No Root) claims to work. There may be some terminal apps that comes with BusyBox binary. I've not personally tested any such terminal app but it is easy to understand that their biggest drawback is: you can't make any or much good use of them using adb.
There is an approach however, which appears to work for any Android version above 4.2 (based on my tests). /data/local/tmp
is a directory which can be edited by shell
user. adb shell
grants you the remote shell on device and login as the same user.
All you've to do is put BusyBox/Toybox binary into /data/local/tmp
and create symlinks for the utilities in the same directory. You can use the following steps for that.
(Requires adb setup in PC.)
adb push LOCAL_FILE /data/local/tmp/
# replace LOCAL_FILE with the file path of toybox/busybox binary in PC
adb shell
chmod 755 /data/local/tmp/FILE
# setting appropriate permission on pushed binary file. Replace FILE with the name of the binary you pushed in first step. Recommended is to use a single word as a name with all lower-case letters
box=/data/local/tmp/FILE
# setting up a local variable for usage in next step. Replace FILE as appropriate
$box | $box sed 's/\ /\n/g'| $box sed '$d'| while read line; do $box ln -sf /data/local/tmp/FILE /data/local/tmp/$line; done
# We're executing the binary referenced by $box to list all utilities, followed by creation of a list and then for each item in the list, we're creating a symlink in a directory.
Izzy has recommended the most straightforward way to place symlinks for BusyBox binary.
adb shell /data/local/tmp/FILE --install -s /data/local/tmp/ # Replace FILE as appropriate. --install -s will create desired symlinks for you in a directory. Directory's path is provided next to it.
All those tools can now be accessed using the absolute path /data/local/tmp/TOOL
. Replace TOOL with the utility name. Example usage of calling find command:
adb shell /data/local/tmp/find --help
adb shell /data/local/tmp/FILE find --help
# alternative way of using a tool
For interactive shell sessions, you can add the location of FILE into $PATH using export command:
export PATH=/data/local/tmp:$PATH
# this is prefixing /data/local/tmp into the existing value of $PATH. export would make sure that sub-shells see the same value in $PATH
Done that, you can now use find or another BusyBox/Toybox utility in this manner:
adb shell
find --help
It is to be noted that changes in $PATH are applicable only for the current shell session. It means that every time you launch a shell using adb, you would've to export $PATH.
That said, there is no Android-only solution for non-interactive shell sessions other than of finding a way to create a variable whose existence and value would persist beyond the current shell session in your PC, not Android. Example:
adb shell $lolcat
# $lolcat is a temporary variable in my shell on PC and it was assigned the value /system/xbin/toybox. My bash shell is replacing $lolcat with its value and then passing it to adb shell (or you can say, it first expanded the variable and then executed the whole command)