• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Root Using the terminal

Some questions for rooted droid users:
How much are you using the terminal, and what kind of stuff do you use it for? Which emulator are you using? I like the idea of tinkering with command line on my phone, using it to do simple stuff, partly as a fun way to get reacquainted with it, as I use to use command line a little bit with XP and ubuntu.
I've batted around between Better Terminal Emulator Pro and Terminal Emulator. One confusing thing is that they seem to use different commands. For example, in terminal emulator the help command brings up a help menu, in TEP it is unrecognized as a command. What accounts for these differences?
Lastly, any suggestions for lists of commands and tips for using them, in a way that will work with these emulators?
 
I am a big time linux geek and I actually use the shell quite a bit. The Android Terminal Emulator works just fine for me. However, I did go through great pains last night to extract the shell from the Sholes rom as it is much much better if you are going to be using it much.

The shell that comes stock is a stripped down Bourne Shell. The Sholes Rom has a pretty nifty Bourne Again Shell (BASH), that adds more features, but most importantly nice colors and more info.

When you use the shell in linux for the most part you are not really using built in shell commands, but built in script files. These files reside in /system/bin for the Droid. You can do an 'ls' on that directory and see what is there.

A couple of things to help though:

"ls -l" - Gives a listing of the current directory with expanded information (doesn't work in the basic shell)
"du -csh" - gives a disk usage of each file/directory in the current branch.
"cat filename1 > filename2" - For some reason, the Droid does not come with a copy (cp) command. This works in the exact same way.

Let me know if there is anything in particular you are looking for. One thing that helps is understanding redirection and pipes.

'>' Means to put the output of the command into a file as specified. Overwrites the file.
'>>' Means to put the output of the command into a file, but does not overwrite the file, it places it at the end.
'|' - means pipe the output of one program into another program.
'<' - means to use the specified file for the input to the program.

If anyone wants to use the shell that came with the Sholes rom, I can post some instructions on how to do that. It really isn't worth it unless you plan on using the shell a lot.
 
  • Like
Reactions: bookie and hortstu
Upvote 0
thanks for the reply and info darrin. the terminal emulator i use is the one by Jack Palevich. I see from the help file that it uses GNU bash 4.1.0(4), so is the Android Terminal Emulator you say uses Bourne the google product? I read online that people didn't have much success with that one so I stayed away from it. I also downloaded the Better Terminal which uses ash.


I suppose i prolly dont need the fancier shell you referenced, as I sitll don't really know what the capabilities of the two emulators I have now are. As I said, still a command line nob, any books/guides/websites you can recommend?
 
Upvote 0
thanks for the reply and info darrin. the terminal emulator i use is the one by Jack Palevich. I see from the help file that it uses GNU bash 4.1.0(4), so is the Android Terminal Emulator you say uses Bourne the google product? I read online that people didn't have much success with that one so I stayed away from it. I also downloaded the Better Terminal which uses ash.


I suppose i prolly dont need the fancier shell you referenced, as I sitll don't really know what the capabilities of the two emulators I have now are. As I said, still a command line nob, any books/guides/websites you can recommend?

No I am using the Android Terminal Emulator. The shell and the terminal emulator are two different things actually. Under settings you can tell the emulator to use different shells. Anyway, it sounds like you have the "good" shell already. I know that I got it when I installed Sholes, but lost it when I updated to Bugless Beast, so I had to hack it back in there.

I can give you several links to some lists and references, but these are all for full-on linux. I am not currently aware of that are specific to android. Here is a pretty good introduction:

Linux Online - Getting Started with Linux - Lesson 6 (2)

The real power in a shell, particularly bash, is scripting. I am just not sure how useful it would be in this phone and how much functionality it would have.

If you have access to Linux I can give you some really good links that cover the bash shell.

Hope this helps. Have fun.
 
Upvote 0
Hello I have a question. I had a HTC Magic i dont know which version of Android was installed. In android terminal commands like su, grep, wc, more... normaly worked. Now I have a new HTC Magic with Android 1.5 and the commands listed above do not work any more in the terminal. So what do i have to do to get these commands working?
 
Upvote 0
Hello I have a question. I had a HTC Magic i dont know which version of Android was installed. In android terminal commands like su, grep, wc, more... normaly worked. Now I have a new HTC Magic with Android 1.5 and the commands listed above do not work any more in the terminal. So what do i have to do to get these commands working?

I don't know anything about the Magic, but it should be pretty similar to the Droid. Is it possible that your other phone was rooted and this one is not? If the super user command doesn't work, I don't think you have root privileges.

The others all available via busybox, but you can't install busybox without root access.
 
Upvote 0
Thanks for the info, it was just the thing that i needed. I have rooted my phone, installed busybox, it took me all day, because I am a Android novice, but now I am enjoing all the new Linux commands. There is just one thing that bothers me, my keyboard doesnt have a "|" key.


To find the "|" key just use the shift key on the soft keyboard when the numbers are shown. You will then find it on the top left of the keyboard beside the < > keys.:)

I have a rooted xperia running 1.6 with R2Ba024 build. works well..

using busybox and note that the --help after the command name brings up the help.

fun playing with the commands:cool: and have installed "scripter" which lets me store and run scripts and also to read them in from a typed hardcopy using the camera if I also install a scanner app. So if someone hands you a script or you see a lot of commands on a website, you can read them in using scripter without typing them in..then edit as you like. Have not used this part yet.:cool:

would be curious to find how to change the prompt to include the path. I have forgotten..think it had something to do with editing a .profile file or something.
 
Upvote 0
I'm interested in possibly attempting this:

LauncherPro Forum &bull; View topic - Fixed Launcher Pro lag when returning to home screen

I would assume that it requires me to use a terminal emulator. I installed one on my Droid, but then didn't know what to do next, to locate the files in question. So here's what I'm wondering.

1. Is this likely to be difficult for someone who's never done anything like this before? I'd love to learn about doing this sort of thing, I just don't know if this will be over my head.

2. If this shouldn't be difficult, could someone link me to (or post) the steps? I did some googling, but didn't find anything especially helpful.
 
  • Like
Reactions: RandyF
Upvote 0
I am a big time linux geek and I actually use the shell quite a bit. The Android Terminal Emulator works just fine for me. However, I did go through great pains last night to extract the shell from the Sholes rom as it is much much better if you are going to be using it much.

The shell that comes stock is a stripped down Bourne Shell. The Sholes Rom has a pretty nifty Bourne Again Shell (BASH), that adds more features, but most importantly nice colors and more info.

When you use the shell in linux for the most part you are not really using built in shell commands, but built in script files. These files reside in /system/bin for the Droid. You can do an 'ls' on that directory and see what is there.

A couple of things to help though:

"ls -l" - Gives a listing of the current directory with expanded information (doesn't work in the basic shell)
"du -csh" - gives a disk usage of each file/directory in the current branch.
"cat filename1 > filename2" - For some reason, the Droid does not come with a copy (cp) command. This works in the exact same way.

Let me know if there is anything in particular you are looking for. One thing that helps is understanding redirection and pipes.

'>' Means to put the output of the command into a file as specified. Overwrites the file.
'>>' Means to put the output of the command into a file, but does not overwrite the file, it places it at the end.
'|' - means pipe the output of one program into another program.
'<' - means to use the specified file for the input to the program.

If anyone wants to use the shell that came with the Sholes rom, I can post some instructions on how to do that. It really isn't worth it unless you plan on using the shell a lot.

How did you go about getting the shell from Sholes? I used to have it but lost it when I switched roms recently :-(
 
Upvote 0
Since you are all having fun in the shell, you may want to log in to your Droid from your laptop or desktop because it's a LOT easier to type in a shell from there, using a normal keyboard, as opposed to the tiny terminal emulator app on the Droid.

I use quicksshd ($1.50 from market) and that allows me to log into my Droid within my local network from a PC. It's very robust and reliable and runs a standard "drobpbear" (sshd lite) daemon.

On your PC end, try downloading freeware client putty.exe (google it) as it's an excellent PC-based ssh client. From there you can connect to your Droid from your big machine, with the username 'root' and the password you supplied to quicksshd on your Droid. You'll think you logged into your regular desktop linux machine instead of the Droid :). All your droid rooted commands will work there. Well, this all assumes you're rooted, of course.

Unfortunately, since Verizon blocks incoming port 22 (sshd) to your Droid from the outside world, it's trickier to log into your Droid from outside your local wifi network via 3G. That's still very doable, though, if you use a port forwarding agent app on your Droid such as ConnectBot. You can port forward your Droid's dropbear port 22 out to a remote linux machine on the internet, then log into your Droid via the port you forwarded to that remote machine. In other words Verizon won't let you into port 22 on your Droid from the outside world, but if you initiate it from your Droid, you can "teleport" your Droid's port 22 out to a remote machine and log in from there.

There may be a lot of gibberish sounding stuff in this post, because there is a lot of information here, especially if you're a linux newbie. Let it suffice to say that if you can decode what I've said, it'll give you the ability to log into your Droid and run a shell on your Droid from anywhere on the internet while your Droid is 3G connected. neall
 
Upvote 0
Yes ndoren, I am with johngalt. Unless there is something else more that can be done with your method(s), it sounds like I would just as soon connect via USB and use adb shell. However the port forwarding part does sound pretty interesting, but I really doubt I'd be in that much of a hurry to access the terminal on my Droid.

If I really missed something, please enlighten this Linux n00b.

Thanks.
 
Upvote 0
The downside to that would be that you'd either have to 1) enable connectBot whenever you wanted to use the shell remotely - which means you have both the phone and the computer accessible, so it is only a matter of finding the USB cable to connect them directly, or 2) You leave the port forwarding on all the time - and then you have unbridled access to your phone b/c of the SSHd running - which means anyone else with *nix skills also has access to the phone if they know the IP address....right?

Or would they still need to log into the remote *nix box first and then get unbridled access to the phone?
 
Upvote 0
John, good questions.

As it turns out, this is a VERY secure way to access your phone. Well, no more or less secure than accessing any linux box via ssh over the internet, which thousands of people do every day. There is no unbridled access to the phone. To log into the phone remotely, you need to supply a password (which you set up within the QuickSshd app).

There are no cables involved... every connection is done via 3G, and all connections are secure. The key is that you can be at one location, and your phone can be anywhere else in the country where it happens to have a 3G connection. In other words, your phone looks like some linux box out there on the internet somewhere, far away, and you remotely log into it. Of course, if your computer is next to your phone, just use a USB cable (or I use SMB/CIFS via wireless and just mount my PC drive to it without cables.

Consider this scenario: Assume someone wants shell access to their phone while at work, but they can't take their phone into the office (for whatever reason). From their car, they use ConnectBot (with port forwards set up) and ssh from their phone to some linux box at home or school. Then, they simply leave that connection active. So, yes John is right that it requires an active ssh connection from the phone to a linux box, and requires the phone to be running the QuickSshd app. No problem, just plug it into the cigarette lighter and fire that stuff up before you leave your car. The port forward involves mapping the sshd port on the phone (port 22) to some remote port on the distant machine (say port 8022).

Now, to access a shell on the phone, you ssh from your office to the linux box that your phone's ssh daemon is port forwarded to. Then once logged onto that machine, ssh to the localhost port (port 8022 in this case) on that machine and viola, you have a shell opened up to your phone.

So, here is the point. Your phone is one place (say, your car). You are another place (work), and you "meet" your phone at some third place, say your linux box at school. Neall
 
Upvote 0
Ok, so maybe that last example is a bit far fetched for you... because your phone is never far from your computer. My phone often is away from me, so I do use it as described above. Also, it's not just about remote shells. You can easily transfer files between your machine and your phone via sftp, even when those two devices are far from one another.

Here is a more practical application of SSH port forwarding, that I use every single day: Unlimited surveillance camera monitoring...

I have an IP-based surveillance camera on my local home network. I also have a desktop linux box on my home network. I can access the video camera via its web-access port 80 when at home via wifi. Now, when on the road, let's say I want to access my home webcam from my Droid. I can use the Seedonk app, but that app sucks because it only streams for a few minutes at a time, and Seedonk costs money. Instead, when on the road, I use ConnectBot on my Droid to ssh to my home linux machine, and I _reverse_ (aka remote) port forward the IP camera's web browser to a port on my Droid. Now, that makes the web cam look like it's attached directly to my Droid, when I'm actually hundreds of miles away! I then use the freebie IP Cam Viewer app (in the market) and tell it the cam is connected directly to my Droid (localhost) at the port I used in ConnectBot port forward. That way, I can have a continuous 24-hour webcam connection to my Droid via 3G without using payed servers utilizing limited connect times.

Hope this all wasn't too confusing. Neall

PS: By the way, you don't need a linux box at home to ssh into your home network and forward ports from an IP camera. Many home wifi routers can run linux, so you can install a custom ROM into your home router (such as DD-WRT into your Linksys router) and you can actually SSH right into your home router from your Droid from anywhere.
 
Upvote 0
John, good questions.

As it turns out, this is a VERY secure way to access your phone. Well, no more or less secure than accessing any linux box via ssh over the internet, which thousands of people do every day. There is no unbridled access to the phone. To log into the phone remotely, you need to supply a password (which you set up within the QuickSshd app).

There are no cables involved... every connection is done via 3G, and all connections are secure. The key is that you can be at one location, and your phone can be anywhere else in the country where it happens to have a 3G connection. In other words, your phone looks like some linux box out there on the internet somewhere, far away, and you remotely log into it. Of course, if your computer is next to your phone, just use a USB cable (or I use SMB/CIFS via wireless and just mount my PC drive to it without cables.

Consider this scenario: Assume someone wants shell access to their phone while at work, but they can't take their phone into the office (for whatever reason). From their car, they use ConnectBot (with port forwards set up) and ssh from their phone to some linux box at home or school. Then, they simply leave that connection active. So, yes John is right that it requires an active ssh connection from the phone to a linux box, and requires the phone to be running the QuickSshd app. No problem, just plug it into the cigarette lighter and fire that stuff up before you leave your car. The port forward involves mapping the sshd port on the phone (port 22) to some remote port on the distant machine (say port 8022).

Now, to access a shell on the phone, you ssh from your office to the linux box that your phone's ssh daemon is port forwarded to. Then once logged onto that machine, ssh to the localhost port (port 8022 in this case) on that machine and viola, you have a shell opened up to your phone.

So, here is the point. Your phone is one place (say, your car). You are another place (work), and you "meet" your phone at some third place, say your linux box at school. Neall

That definitely wfm. Especially the part I boldfaced - that is the important part - with that in place, you're right, no unbridled access.

Ok, so maybe that last example is a bit far fetched for you... because your phone is never far from your computer. My phone often is away from me, so I do use it as described above.

Here is a more practical application of SSH port forwarding, that I use every single day: Unlimited surveillance camera monitoring...

I have an IP-based surveillance camera on my local home network. I also have a desktop linux box on my home network. I can access the video camera via its web-access port 80 when at home via wifi. Now, when on the road, let's say I want to access my home webcam from my Droid. I can use the Seedonk app, but that app sucks because it only streams for a few minutes at a time, and Seedonk costs money. Instead, when on the road, I use ConnectBot on my Droid to ssh to my home linux machine, and I _reverse_ (aka remote) port forward the IP camera's web browser to a port on my Droid. Now, that makes the web cam look like it's attached directly to my Droid, when I'm actually hundreds of miles away! I then use the freebie IP Cam Viewer app (in the market) and tell it the cam is connected directly to my Droid (localhost) at the port I used in ConnectBot port forward. That way, I can have a continuous 24-hour webcam connection to my Droid via 3G without using payed servers with limited connect times.

Hope this all wasn't too confusing. Neall

Not for me it isn't lol. I have had enough experience with *nix to follow your gist.

I might look into this soon enough....
 
Upvote 0
I am a big time linux geek and I actually use the shell quite a bit.

darrin2520, perhaps you point me in the right direction:

new to Android, only have it 1 week

I have Atrix, rooted. rootcheck tool says I have busybox with '...,wget,.....'

I can open terminal, 'ls' works, 'grep' works, etc

how do I access and use say 'wget' that apparenly is present with busybox ?

many thanks for any pointers
 
Upvote 0
rild
resize2fs_recvy
bluetoothd
reboot
radiooptions
awb_camera
ping
netsharing
racoon
applypatch
pppd
netcfg
aparse
mtpd
mediaserver
akmd
mscompress
logwrapper
monitorMTD
logcat
mmclient
newfs_msdos
linker
mmcamera_test
iptables
mke2fs_recvy
ip
wipe
id
insmod
date
smd
lsc_camera
watchprops
installd
top
getevent
netstat
wpa_supplicant
keystore
vmstat
dmesg
umount
mkdir
hciattach
dumpcrash
notify
start
wlan_loader
keypress
sleep
gzip
rmmod
printenv
vold
pm
setprop
htclogkernel
dvz
renice
hd
ls
udhcpd
mount
fsck_msdos
lsmod
dumpsys
monkey
route
toolbox
chmod
fbtool
dumpstate
schedtop
system_server
getprop
ps
sendevent
df
stop
flash_image
ioctl
e2fsck_recvy
dhcpcd
svc
su
input
wifitools
dumplayer
surfaceflinger
ime
chown
rmdir
dexopt
sound
rm
vptest
setconsole
iftop
debuggerd
mv
debug_tool
cmp
uevent
kill
snd
ln
log
bugreport
cat
dbus-daemon
sync
spkamp
dd
sh
ifconfig
dalvikvm
btipsd_cli
snd8k
servicemanager
btipsd
cam_ins_spmo
shutdown
service
app_process
bootcomplete
setmic
sdptool
bootanimation
am
ser2net
bmgr
schedtest
rsync
bma150_usr
 
  • Like
Reactions: aramic
Upvote 0
rild
resize2fs_recvy
bluetoothd
reboot
radiooptions
awb_camera
ping
netsharing
racoon
applypatch
pppd
netcfg
aparse
mtpd
mediaserver
akmd
mscompress
logwrapper
monitorMTD
logcat
mmclient
newfs_msdos
linker
mmcamera_test
iptables
mke2fs_recvy
ip
wipe
id
insmod
date
smd
lsc_camera
watchprops
installd
top
getevent
netstat
wpa_supplicant
keystore
vmstat
dmesg
umount
mkdir
hciattach
dumpcrash
notify
start
wlan_loader
keypress
sleep
gzip
rmmod
printenv
vold
pm
setprop
htclogkernel
dvz
renice
hd
ls
udhcpd
mount
fsck_msdos
lsmod
dumpsys
monkey
route
toolbox
chmod
fbtool
dumpstate
schedtop
system_server
getprop
ps
sendevent
df
stop
flash_image
ioctl
e2fsck_recvy
dhcpcd
svc
su
input
wifitools
dumplayer
surfaceflinger
ime
chown
rmdir
dexopt
sound
rm
vptest
setconsole
iftop
debuggerd
mv
debug_tool
cmp
uevent
kill
snd
ln
log
bugreport
cat
dbus-daemon
sync
spkamp
dd
sh
ifconfig
dalvikvm
btipsd_cli
snd8k
servicemanager
btipsd
cam_ins_spmo
shutdown
service
app_process
bootcomplete
setmic
sdptool
bootanimation
am
ser2net
bmgr
schedtest
rsync
bma150_usr

Could someone please list what each cmd does, so someone doesn't ruin their phone?
 
  • Like
Reactions: aramic
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones