Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a standard way to reverse the output order of a terminal output, ie:

~/Developer $ command0 
-bash: comman0: command not found 
~/Developer $ command2 
-bash: command2: command not found 
~/Developer $ command3 
-bash: command3: command not found 
~/Developer $ 

would be displayed as:

~/Developer $ 
-bash: command3: command not found 
~/Developer $ command3 
-bash: command2: command not found 
~/Developer $ command2 
-bash: comman0: command not found 
~/Developer $ comman0

I feel always having your prompt at the bottom is counter intuitive a more effective way of presenting the output woud be to reverse the output order. How might I go about implementing this? Specifically where output portion of the OSX terminal program defined?

share|improve this question
This would confuse me, but I applaud your efforts. On of linux/unix/open source major lesssons is that One Size Does Not Fit All. –  Bruce Ediger Apr 3 '12 at 17:18
I think this is not possible at all unless you change the source code of the shell (e.g. bash). –  Renan Apr 3 '12 at 17:20
You'd need to hack more than just the shell. Terminals have been scrolling this way since they were electromechanical. At the very least, I'd say you'd need to hack a terminal emulator, maybe also a shell. –  Alexios Apr 3 '12 at 17:31
This is actually counter intuitive. Have you noticed the ENTER key arrow? It points to the line below, not above. –  dresende Apr 3 '12 at 18:07
Is there a way to grab the items of out put from a terminal, my thought is to create some sort of wrapper which grabs each of these output items, treats each of them similar to how tweets are posted with the newest always apear on top and sticking the input prompt at the top of the Wrapper UI. –  rudolph9 Apr 3 '12 at 21:13

2 Answers 2

Unfortunately, this will be fairly difficult. The protocol between the applications and the OS-X terminal is a variant of the VT100 / ANSI terminal control protocol, specifically the XTerm protocol.

That includes a bunch of assumptions about screen position, etc, that would be challenging to remap to a world where the display was reversed.

Even worse, all your terminal emulator gets is a string of "put this character at this position" type commands. There is no distinction made between the command prompt and the output of a command run by it, so you can't do one thing for both parts - at least, not without cooperation from the shell underneath.

The shell, and the programs, assume that the screen proceeds upwards - new data at the bottom, and carries on downward forever.

You could, at least theoretically, have your terminal emulator modified so that it displayed lines in reverse order - the "bottom" line first, and so on up to the "top" line at the bottom of the screen.

That would reverse the order of lines in command output, though, so the rest of the content would pop out backwards too. If you wanted the commands (eg: ls, cat) to run "down" but prompts to move "up" life is harder.

I don't know any software that implements this.

share|improve this answer

In bash this will display the current prompt/command at the top, and its output below, but with no scrolling or previous commands:

PROMPT_COMMAND='tput cup 0 0; tput el; tput el1'

This function will put previous commands below, but you have to pipe each and every command to it individually. Unfortunately, exec > >(f) can't help with this as it redirects the whole of bash, not individual commands. Here's the function:

f () { tee ~/.STDIN | wc -l | xargs expr 1 + | xargs tput il && cat ~/.STDIN; }

Then run every command like:

command args |f

It saves the output, creates a number of blank lines equal to length+1, then puts the output back in. You can tag a line on at the end that will display a fake prompt or horizontal rule if you like. E.g.

printf '%*s' $COLUMNS | tr ' ' _;

As a crap but automatic alternative to this whole function thing, we can add a command to the end of our earlier $PROMPT_COMMAND that clears a somewhat arbitrary 11 lines:

PROMPT_COMMAND='tput cup 0 0; tput el; tput el1; tput il 11'

You can also use tput -S to avoid multiple binary calls.

I got the $PROMPT_COMMAND from https://github.com/swirepe/alwaysontop .

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.