cmd to find used cmd in linux
Using the
history
Command: You can view a list of previously executed commands along with their line numbers by typinghistory
in the terminal. Then, you can refer to a specific command by its line number.Using the
Ctrl + R
Shortcut: PressingCtrl + R
in the terminal will initiate a reverse search. You can start typing a portion of the command you want to search for, and the terminal will display the most recent matching command. PressingCtrl + R
again will cycle through older matches.Using
!!
: Typing!!
in the terminal will execute the last command used. This is useful if you want to quickly repeat the previous command.Using
!n
: You can execute a specific command from your history by typing!n
, wheren
is the line number of the command you want to execute. For example,!123
will execute the command on line 123 of your command history.Using
history | grep keyword
: You can search for commands containing a specific keyword by piping the output ofhistory
togrep
. For example,history | grep ssh
will display all commands related to SSH.
These methods should help you quickly find and reuse previously used commands in your Linux terminal.