Go back to the last command

Suppose you type a command in terminal after Enter you will see a list which more than one page. Now you want to read the result from the beginning and you should scroll up. So if you put some commands before your last one its a bit difficult to scroll the the last one --at least for me -- So I need any key switch which show the screen from the last command.

ps: I want to screen show the last command by key switch. Is there any key switch like CTRL+ L which clear the screen. less command show the screen page by page.


There isn't one as far as I know. You have a few choices though:

  1. Pipe the output through less or more

    command | less
    
  2. Hit the up until you find the command you ran and run it again (optionally using less or more again).

  3. Run the previous command through less using history expansion.

    !! | less
    
  4. Use a terminal that supports searching through the scroll back. The image below is showing my preferred terminal, terminator (installable with sudo apt-get terminator) but Ubuntu's default terminal also supports this. Just hit Ctrl Shift F to show the search bar. If you then search for either the command's name or your username (which appears in your prompt) you will be taken directly back to the last command:

    enter image description here


Pipe the result through less,

some-command | less

From the man page;

Less is a program similar to more (1), but which allows backward movement in the file as well as forward movement.


So basically you want it to automatically scroll to the last prompt, and the command that was run from it? I don't think this is possible with current versions of terminal unless you use a find function.

However as an alternative, you can colour in the prompts so that it is easier to work out where they are: enter image description here

You can do this in Ubuntu* by going to the ~/.bashrc file, and uncommenting this line:

#force_color_prompt=yes

to:

force_color_prompt=yes

You can then save it and run source ~/.bashrc and see the changes straight away.

*In other Linux OS's, on versions of Ubuntu without this version of ~/.bashrc, just copy lines 31 to 78 (only most of it is needed) of this and then uncomment #force_color_prompt...