[CENTOS] Linux command history search "Ctrl + r" that is scary to get used to

I posted it because I felt that there were some dangerous cases when using it. Execution in the command history An NG update / deletion command was displayed by mistake. .. ..

What is command history search "Ctrl + r"?

A function that allows you to search the previous command history based on keywords.

$ #In the terminal "Ctrl"+Press "r" to enter search mode and start accepting input
(reverse-i-search)`': 
$ #For example, if you type cd, the most recently executed cd command will be displayed.
(reverse-i-search)`cd': cd /var/www/
$ #In the above state, "Ctrl+Press "r" to display the previous history
(reverse-i-search)`cd': cd html

When did you think it was dangerous?

It is often used when searching for a connection command with Ctrl + r when logging in to the DB from the terminal (psql), but the latter half of the command search result contained a description to execute update SQL that would be NG if executed now. .. ..

$ #"" In the latter half of the psql command-There was "f" (execution by specifying the SQL file)
(reverse-i-search)`psql': psql -h ${hostname} -U ${User name} -d ${Database name} -f {SQL file that is not executed now}

I accidentally pressed Enter, but it was safe because I noticed it when I was prompted to enter the password. I was horrified to think that I would have executed it without noticing it. .. ..

at the end

The possibility of an accident may be reduced if you are aware of the risks associated with the commands you use on a daily basis. In the above case, I wondered if the command history was displayed with history | psql and copy and paste was still less likely to cause an accident. It's less efficient. ..

Recommended Posts

Linux command history search "Ctrl + r" that is scary to get used to
Chown command as root, which is dangerous to get used to chmod command
[Linux] Search command
What is Linux? [Command list]
First get used to sending