Question

Have you ever used a command in the Terminal, but then later forgot what you typed, and wished there was some way that you could view the last used commands?

Était-ce utile?

La solution

There are many ways to search through your command history. Here are 3:

  1. use the up and down arrows on your keyboard when at the command prompt.
  2. use the history command.
  3. Simply press : Control + R when at the command prompt.

E.g : Control + R , then write php

enter image description here

Autres conseils

I often use bash-builtin command "history" to search for a certain command, e.g. to get the last sudo command type:

history | grep sudo | tail -n 1

gives the last command (with number) with sudo in it. "tail -n 1" gives the last matched line. Then use

!<number>

to execute exactely this command.

!-1

executes the last command, by the way. works well in bash.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top