28

When I connect to Android using "adb shell" and run certain commands such as "vim" or "mc", they are restricted to a "window" of 25x80 characters. Since I'm connecting from a desktop computer where xterm has a much higher resolution, I'd like to use it.

How do I resize this console window to e.g. 60x156 characters?

4 Answers 4

27

The answer is

stty rows 60 cols 156

A follow-up question is how do I determine the size of my xterm I'm connecting from so that I can pass it to stty automatically (using a script)?

6
  • Great that you found the solution to your own problem. Don't forget to "accept" it when you are able. However, don't include another question; this isn't a discussion forum. You should open a new question. If it's related you can link to this one from the new question.
    – ale
    Oct 26, 2011 at 20:40
  • 2
    Is there a way to tell the android shell to resize automatically to fit the screen size? Similar to the way it's done on other terminals in Unix? Apr 6, 2013 at 20:19
  • 1
    i tried this, but it said "/system/bin/sh: stty: not found"... does it have to be installed or something?
    – Brad Parks
    Sep 24, 2013 at 13:44
  • 2
    For those who dont know BuxyBox: BusyBox is an app. that has a lot of common unix tools "inside" of it - it's particularly designed for embedded systems. To try it install BuxyBox app on your rooted android. Oct 10, 2013 at 18:19
  • 1
    How make this permanent?
    – JohnyTex
    Aug 4, 2017 at 9:27
24

Typing resize after connecting to the device works for me:

shell@android:/ $ resize
COLUMNS=192;LINES=44;export COLUMNS LINES;
1
17

If you're on a recent release of Android that uses mksh you can simply do:

COLUMNS=156
LINES=60
-1

Using mksh, I had to run eval $(resize).

The resize command outputs the shell commands COLUMNS=#;LINES=#;export COLUMNS LINES; to stdout, but it does not actually execute them. For that, you can use eval and put it in your .profile or shell rc file. While you're in there, you can add an alias for easy resizing after the actual window is resized.

$ grep resize ~/.profile
eval $(resize)
alias rsz='eval $(resize)'
2
  • 1
    You shouldn't have to eval the result. resize by itself just works (it does the proper ioctls) Feb 26, 2016 at 23:54
  • In my case at that time (8.5 years ago), I had to use eval. I don't know why, but resize alone was not enough. I was just offering this up as a suggestion based on personal experience. ¯_(ツ)_/¯
    – knh
    Aug 15, 2022 at 4:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .