News How To View Your Command History in Linux

clsgis

Distinguished
Sep 15, 2013
4
0
18,510
0
I use that reverse history search all the time. But not the way you showed it. Control-r is an emacs thing. I've been using vi (elvis, nvi, vim...) since it was new. Its visual command language is in muscle memory. I'm never gonna learn emacs.

So the first thing I do with a new Linux system is add this line to /etc/inputrc
Code:
set editing-mode vi
Any program that uses the GNU Readline library will now read lines in vi mode, not emacs mode. The Bash shell, the Python interactive interpreter, the mysql "monitor," even the lowly FTP client. Each of those things will remember your typing-into-them history.

When the shell is reading lines in vi mode, you just hit escape and your shell prompt turns into a one line vi window. Most vi "visual" commands work as you would expect. You can cut and yank and paste. But instead of :x or :wq to save and quit, you just hit enter when the command looks right.

To try it, type
Code:
set -o vi
into the shell, to put it in vi mode temporarily. Now you can go
escape k k
and you are scrolling up in your command history. because k is the vi command to go up a line. Hit enter when you see a command you want to run again. Or change it with vi commands, and run the changed command. To find the last time you ran ps,
escape /ps enter
because / is the search command in vi.


link
 
Last edited:

clsgis

Distinguished
Sep 15, 2013
4
0
18,510
0
So the first thing I do with a new Linux system is add this line to /etc/inputrc
That's a lie. The first thing is change the default passwords. Second thing is update anything that was stale in the installation medium. Third thing is /etc/inputrc 🆒
 

ASK THE COMMUNITY