How do I install missing command line tools onto an Android device?


Question

Android installations do not always have all the tools one would expect to have on a Unix-like system.



For example, right now I have a problematic device which doesn't have find CLI utility. I mean, this is what I get while in adb shell:



$ find
/system/bin/sh: find: not found


Also:



$ /system/bin/toolbox find
find: no such tool


This particular device is running Android 5.0 (plus some proprietary additions by LG, I guess), but the question is for all Android versions, of course.



Is there a standard procedure for installing native/CLI tools (such as find), on Android? (A package manager?) And, anyways, how to do it in the most correct way?


Answer

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.


What is Toybox?



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 .


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 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)

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes