A Better Android Shell

Only for rooted phones!

This little tweak was tested on the following device:

Phone: Samsung J5 Prime SM-G570M
System: Nougat 7.0
ROM: BeltaOS
Internal Memory Path: /sdcard

Accessing the Android's shell for the first time can be disappointing. One is expecting a fully featured shell or at least something, a history functionality at the very least. But that's not the case, it is a pretty standard busybox shell with no colors, no nice prompts, no history, no editor such as nano, just a raw shell!

I'll help you setup a nicer shell, with some nano editor, colors, aliases, custom commands and a history.

I'll not cover shell connectivity. To access the Android's shell you can use any one of the many sshd server apps in the Play Store or adb. I recommend the Server Ultimate Pro app. You can buy it here:


It is a paid app but well worth it. Clean design, easy to use, reliable and it has servers for services you might not even heard about. At the writing of this tutorial it supported the following protocols:

Caddy, CVS, DC Hub, DHCP, UPnP, DNS, DDNS, eDonkey, Email (POP3 / SMTP), FTP Proxy, FTP, FTPS, FTPES, Flash Policy, Git, Gopher, HTTP Snoop, ICAP, IRC Bot, IRC, ISCSI, Icecast, Lighttpd, LPD, Load Balancer, MQTT, Memcached, MongoDB, MySQL, NFS, Node.js, NTP, NZB Client, Napster, Nginx, PHP, PXE, Port Forwarder, RTMP, Remote Control, Rsync, SIP, SMB/CIFS, SMPP, SMS, Socks, SFTP, SSH, Server Monitor, Styx, Syslog, TFTP, Telnet, Time, Torrent Client, Torrent Tracker, Trigger, USB/IP, Unison, UPnP Port Mapper, VNC, VPN, Wake On Lan, Web, WebDAV, WebSocket, X11, XMPP

You can download a 7-day trial of Servers Ultimate here:


Download Nano

I did not build this, it is a pre-compiled version of nano, but works just the same and it will suffice!

You can download it here: nano 2.2.6 arm.zip

Setup nano and it's support files

Copy the nano226arm.zip file to your phone's internal storage via your favorite method and connect to the shell. I'll assume that the path for the internal storage is /sdcard. Change it as needed.

We need to su before we issue these commands to allow the proper permissions to be applied to the extracted nano files and also to remount the system partition. So su first!

cd /sdcard
unzip nano226arm.zip

This will create a directory called system in the sdcard directory, and nano files will be inside of it.

Now remount the system partition as read/write, so we can copy stuff there:

mount -o rw,remount /system

Move nano's binary and support files to their proper paths:

mv /sdcard/system/xbin/nano /system/xbin
mv /sdcard/system/etc/terminfo /system/etc

You can delete the rest of the /sdcard/system folder that was created during the extraction process, it is not needed.

rm -rf /sdcard/system

Make nano's binary executable:

chmod +x /system/xbin/nano

Everything is in place for nano to work, but since we have no terminfo variable set in our shell nano won't start. We'll set these variables in a ash.rc file later on.

For now execute the exports manually to test nano:

export TERMINFO=/system/etc/terminfo
export TERM=linux

It should work, and you should be seeing nano's screen. Exit nano by pressing CTRL+X

Unless you have an absurdly small terminal window on your PC you'll notice that nano's screen size is tiny, smaller than your terminal window in fact.

We can fix that setting up stty's column and row sizes to match our pc's default terminal size. Mine is 32 rows and 105 columns. So set the stty size like this:

stty rows 32 cols 105

Try opening nano again. Now the size of it should fit the size of your terminal.

Of course as soon as you exit the shell the stty size and the exported environment variables will be lost. To prevent this from happening we make the system load a profile file with all the variables and aliases we need, and we'll do that using the ash shell, not the sh one.

Setup ash shell and it's rc file

The default is sh. The simplest way to use the ash shell instead of sh is to call ash from within the default sh every time we login.

If you run the ash shell command with the -l flag it will load the /system/etc/profile rc file. By the way that file did not exist on my Galaxy J5 Prime (Nougat).

My approach to this is to keep all these bash support files in one place inside the internal sdcard of the device. This way I can access and edit them on my pc with easy. It is also easier to make backups of these files if they are right there in the sdcard directory.

So let's create a directory that will hold these files in the internal storage sdcard directory. I'll name it System:

mkdir /sdcard/System

Create an empty history file, so we can set the HISTFILE variable. I've added the .txt extension to the file in order to open it easily when double clicked via GUI.

touch /sdcard/System/history.txt

Now create a file in your PC called ash.rc and either paste the code below in it, or create your own aliases and shell stuff.


alias ..='cd ..'
alias ls='ls -lsahF'
alias la='ls -ACk'
alias ns='netstat -alW | sed -n -e '1,/unix/p''
alias profile='nano -w /sdcard/System/ash.rc'
alias p='ping -c 3 $1'
alias rmd='rmdir $1'
alias reload='source /system/etc/ash.rc'
alias maclean='find . -name "._*" -exec rm -v {} \; && find . -name ".DS_Store" -exec rm -v {} \; && find . -name "__MACOSX" -exec rm -rv {} \;'
alias psg='ps -A |grep -i "$@"'
alias pause='kill -STOP "$@"'
alias unpause='kill -CONT "$@"'
alias nano='nano -w $1'

h () { history | grep "$*" | cut -c 8- ; }
gr () { grep -r "$*" ./ ; }
k9 () { for A in $(ps -A | grep $* | grep -v grep | awk '{print $1}') ; do kill -9 "$A" ; done ;}
mkd () { mkdir -p -- "$1" && cd "$1";}

export EDITOR='nano'
export TERMINFO=/system/etc/terminfo
export TERM=linux
stty rows 32 cols 105

 PS1="\n Droid \[\e[34;1m\][\[\e[0;m\]\w\[\e[34;1m\]] \[\e[37;1m\]\[\e[0m\]$ "

Save the ash.rc file and copy from your PC to the /sdcard/System directory we've created earlier inside the phone. This will be the rc file the ash shell will load and use as a profile.

Remember, by default ash loads the profile from /system/etc/profile. Since that file does not exist in this path we'll create a symlink in this path pointing to our newly created ash.rc in the /sdcard/System directory:

 ln -s /sdcard/System/ash.rc /system/etc/profile

Almost set!

Now all we need to do is to call the ash shell at every logon. To do that edit the sh's shell rc file at /system/etc/mkshrc and add the ash command at the end:

nano -w /system/etc/mkshrc

Add this at the very bottom:

ash -l

Press CTRL+O to write the file and CTRL+X to exit nano.

Thats it! Logout from the android shell then log back in.

You should now have a better shell with colorful listings and a styled PS1, properly stuffed with your aliases, functions and variables. Plus some native editor, nano in our case.

ash shell

{{ message }}

{{ 'Comments are closed.' | trans }}