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

Terminal command history keystroke UNIX
Nifty little feature of the Terminal. If you press the up and down keys, it'll cycle through a history of the commands that you've entered. Handy for that annoying directory that you misspelled trying to switch. Just press the up key and make the necessary changes.

[Editor's note: If you're new to the Terminal and UNIX in general, I highly recommend a couple of things. First, read Neal Parikh's Terminal Guide, linked in the top right box off the macosxhints' home page. Second, download ManThor, a Cocoa application for reading UNIX manual pages ("man pages"). Install and launch ManThor (which features formatting, printing, and searching - all free!) and then type "tcsh" in the search box. The man pages for tcsh are very very thorough, and explain about the history buffer as well as a number of other cool features. Well worth the reading time!]
  • Currently 4.25 / 5
  You rated: 5 / 5 (4 votes cast)

Terminal command history keystroke | 8 comments | Create New Account
Click here to return to the 'Terminal command history keystroke' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
History Buffer is broken
Authored by: Chas on Oct 22, '01 04:20:20AM

Unfortunately, the history buffer does not function correctly. It should save the buffer when you quit but it doesn't. Try this test. Open a terminal session, do any command, something offbeat you'd recognize like "man man". Then quit the terminal (don't just close the window, quit the app). Now run Terminal again, and when the term window appears, hit the up arrow. Your last command (in our example, man man) should appear. It doesn't. Something else appears instead.
As far as I can tell, the commands you used in your very first terminal session after installing MacOS X are permanently saved into the buffer. I get the same history buffer every time I open a new Terminal session. This is not how it is supposed to work. Does anyone know a fix for this?

[ Reply to This | # ]
How about this ?
Authored by: khaled on Oct 22, '01 07:33:10AM


On a Solaris 7 machine back at the university, we used to type in a command in the terminal that lists the last 10 commands or so, anyone knows how to do this with OS X ? I can't seem to rememer that command.

Thanks all.

[ Reply to This | # ]
How about this ?
Authored by: SeanAhern on Oct 22, '01 11:47:05AM

Try "history".

[ Reply to This | # ]
History Buffer is broken
Authored by: percy on Oct 22, '01 08:52:54AM

That's strange. For me, it's working perfectly. Anytime.

[ Reply to This | # ]
History Buffer is broken
Authored by: bradleysmith on Dec 05, '01 04:17:17PM

Not sure what causes it to break but fixing it is easy: -

1. In you home directory rm .tcsh_history
2. pico .tcsh_history
3. Save file (ctrl-o I think)
4. Exit pico.
5. Job done!

I think I had this problem because I logged in from wok using ssh and it remembered my ssh login history!


[ Reply to This | # ]
History Buffer is broken
Authored by: bradleysmith on Dec 05, '01 04:49:35PM

Okay, my last post was wrong.
The problem occurs if you don't type 'exit' to log out and instead just hit Command-Q


[ Reply to This | # ]
^r search through history
Authored by: Cadre on Oct 22, '01 09:17:48AM

Press ^r (control r)

A new prompt "bck:" will arrise below your normal prompt. Start typing and whatever you type will search backward through your history file (and will be displayed). Press enter to accept. This is one of my favorite key bindings.

Apple did a very good job with the default shell config files, better than any distribution I've ever used.

[ Reply to This | # ]
Look into shells
Authored by: SeanAhern on Oct 22, '01 06:04:04PM

A lot of these are features of the shell that runs within a Terminal, and has nothing to do with the Terminal per se. All of the modern shells have "command line editing", which allows you to recall previous commands and edit them, either with emacs or vi keystrokes. Read more about command line editing here.

Specific shells that some people like are tcsh, ksh, bash, and zsh (my personal favorite). Check out a man page about them ("man tcsh") to learn more about how to use them well. You can also check out Freshmeat ( for more information about particular shells (and other UNIX programs).

[ Reply to This | # ]