T
T
thedophamine2018-01-28 18:51:56
linux
thedophamine, 2018-01-28 18:51:56

Where can I read about `!!` in bash?

I knew about !!it, it launches the last executed command. But I accidentally discovered something similar to aliases:
!1it displays for me sudo apt-get upgrade
!2it displays for me it shutdown -r now
!55displays for me nvm ls --lts
I understand that this is the id of some events, but I didn’t understand where they come from (they are clearly "outdated", some of these commands I long time no input).
Please share where this behavior is described and how to saddle it correctly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Romanov, 2018-01-28
@thedophamine

!n runs the nth command in history.

A
aar, 2018-02-01
@andranique

1. The command history 10will display the last 10 commands typed.
If it's simple history, then it will print in order from 1 to 1000 - the number specified in the variable (in my case, these are 1000 commands) For example:$HISTSIZE

[email protected]:~>  history 6
 1  ls -l                                                                        
 2  ls -la                                                                         
 3  ls -lh                                                                        
 4  sudo zypper dup --no-allow-vendor-change                                       
 5  sudo zypper se virtualbox
 6  history

Accordingly, if we type !3, then the command will be executed, ls -lhetc.
2. You can also search for commands using Ctrl+r, and then enter the first few letters of the command and it will return the closest to the input.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question