Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Fast command history scrolling in Terminal Apps
Most shells support scrolling through recent commands by using the up and down arrow keys at the prompt. Terminal.app also supports positioning the cursor by option-clicking at any point in the terminal window. You have to enable this feature by checking the "Option-click to position cursor" box in the Terminal's Window Settings -> Emulation panel.

Use these two features together to quickly scroll up or down through your your last n shell commands by clicking n lines above or below the command line. For example, press the up arrow, then option-click five lines up to bring back the fifth previously executed command.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[18,652 views]  

Fast command history scrolling in Terminal | 13 comments | Create New Account
Click here to return to the 'Fast command history scrolling in Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Fast command history scrolling in Terminal
Authored by: TvE on Dec 01, '04 11:51:27AM

Hmm - so I have to click at a command I can't see? I don't think I'll use that socalled feature :-)

I'd rather use the CTRL-R "Reverse-i-search" feature.

EG.: To search the history for the last SSH command type "CTRL-R" and start typing "SSH <beginning of servername or IP number>" and bingo the whole command is found from the history.



[ Reply to This | # ]
Fast command history scrolling in Terminal
Authored by: azraq27 on Dec 01, '04 12:24:54PM

Wow, that control-R thing is great! I've never seen that before.

I always use "history | grep [text]" to find previous commands, and then !### to reuse them.

For example:
Lotus:~ bill$ history | grep ssh
480 ssh me@test
Lotus:~ bill$ !480

That command-R thing is sweet.



[ Reply to This | # ]
Fast command history scrolling in Terminal
Authored by: erikh on Dec 01, '04 04:26:46PM

Note that if you know what you're goign to be doing:

!ssh

works just as well - and across most shells.

It's nice when you do this:

vi foo
sh foo
!vi
!sh
(ad nauseam...)



[ Reply to This | # ]
run last command containing ...
Authored by: hayne on Dec 01, '04 06:57:33PM

If you want to re-run a command but don't know what it started with, or don't want the last version of that command, you can use !?

E.g. run the following commands:
ls /System
ls /Users

Now run the following:

!?Sys

and it will redo the first of those two 'ls' commands.



[ Reply to This | # ]
Fast command history scrolling in Terminal
Authored by: fracai on Dec 01, '04 01:58:10PM

I find this to be more of a bug than a feature. For example, if a command you're typing out is long enough to wrap to the next line, option-clicking near the beginning of the command (ie. the first line of the two line command) you'll also see this history scrolling. option-click seems to issue arrow keys in order to reposition the cursor and therefore breaks with multi-line commands.

the !### tip is nice though. I would use grep, but didn't know the numbers were actually useful.

---
i am jack's amusing sig file



[ Reply to This | # ]
Fast command history scrolling in Terminal
Authored by: rwmitchell on Dec 01, '04 02:39:19PM

In the tcsh, I use:

bindkey -k up history-search-backward
bindkey -k down history-search-forward

which lets me type the beginning of a command and then just up and down arrow through only those that match.



[ Reply to This | # ]
Fast command history scrolling in Terminal
Authored by: baba on Dec 01, '04 07:14:24PM

I prefer to just do 'his' which I have aliased to 'history' then use the bang operator with the history item number, as in "!32".
The ctrl-r thing doesn't work for me. Perhaps it's bash-specific.



[ Reply to This | # ]
Fast command history scrolling in Terminal
Authored by: EatingPie on Dec 01, '04 07:25:07PM

A few more hints, assuming BASH is your default shell.

Two keys I use FREQUENTLY!

ctrl-p - scroll up through your history.
ctrl-n - scroll down through your history (after going up some).

The "!!" character is also helpful for last command, but you can add to the end of it.

% ls mach.sym
mach.sym
% !! mach_kernel
ls mach.sym mach_kernel
mach.sym mach_kernel
This one works with csh/tcsh as well AFAIK.

---
-Pie


[ Reply to This | # ]

Fast command history scrolling in Terminal
Authored by: TigerKR on Dec 01, '04 10:43:29PM
I added this to my ~/.bash_profile:

alias histsee='echo "Here are the times that was typed into the command line interface:"; echo""; history | more | grep -i '

Works for me.

[ Reply to This | # ]
Fast command history scrolling in Terminal
Authored by: TigerKR on Dec 01, '04 10:45:44PM
This too:

alias histlast='echo "Here are the last 25 commands that you typed into the command line interface:";echo"";history 25'

I'm right 90% of the time, so why worry about the other 3%?

[ Reply to This | # ]
how about:
Authored by: nick on Dec 02, '04 05:02:21AM

alias "his"="history | sort +2 | uniq -f 1 -c | sort +1"

to just print each command once preceeded by how much you used it.



[ Reply to This | # ]
how about:
Authored by: szabesz on Dec 03, '04 06:17:14AM

Wow! That's really cool! Thanks a lot :)



[ Reply to This | # ]
how about:
Authored by: baba on Dec 03, '04 10:10:20PM

Indeed. That is very nice. Thanks.



[ Reply to This | # ]