How to access the history on the fly in Unix?

Are you talking about classic history expansion, or Readline processing? cd !$ on the next input line will substitute in the last argument of the previous line, or M-. or M-_ will yank it using Readline.


If your question is about accessing command history, then try this well-named command

history 

You can also try Ctrl + r, and start typing a command you're trying to remember that you've recently typed.

(reverse-i-search)`cd ': cd mydir/data/

Hit ESC to select the command or exit. This works for me on SuSE at least; not sure about other distros.


It's as simple as Alt + .

$ mkdir lasdfjalsdkjf
$ cd 

Alt + .

$ cd lasdfjalsdkjf