Linux history command to use the detailed

Source: Internet
Author: User

References in the shell

': Strong reference, variable substitution not performed
"": weak reference, able to perform variable substitution
': command substitution, referencing the execution result of the command: another symbol for the substitution of the command: $ ()

Shell command history: History built-in Command
The command for the current shell process is saved in the cache buffer
When the command to exit the shell buffer is saved to the hidden file in its user's home directory:. bash_history

The file that starts with the point number is a hidden file, ls-a can view the hidden file, if we want to execute the command in command history again, only need! Numbers can

678 ls-a
679 Cat. Bash_history
680 VI
681 history
[Root@docker-node1 ~]#!678
Ls-a
.  .. Anaconda-ks.cfg. bash_history bash_logout bash_profile bashrc. CSHRC in.sh. PKI. TCSHRC. Viminfo
[Root@docker-node1 ~]#

So if we're going to execute the last command, then use!! Can

[Root@docker-node1 ~]#!678
Ls-a
.  .. Anaconda-ks.cfg. bash_history bash_logout bash_profile bashrc. CSHRC in.sh. PKI. TCSHRC. Viminfo
[Root@docker-node1 ~]#!!
Ls-a
.  .. Anaconda-ks.cfg. bash_history bash_logout bash_profile bashrc. CSHRC in.sh. PKI. TCSHRC. Viminfo
[Root@docker-node1 ~]#

If you want to perform the reciprocal command, then you can! -You can

682 ls-a
683 history
[Root@docker-node1 ~]#!-2
Ls-a
.  .. Anaconda-ks.cfg. bash_history bash_logout bash_profile bashrc. CSHRC in.sh. PKI. TCSHRC. Viminfo
[Root@docker-node1 ~]#

If you want to execute the last command without looking at the command numbers and referencing the command arguments, you can do the following (only the last command in the command history can be executed, and from the bottom up)

[Root@docker-node1 ~]# Cat in.sh
#!/bin/bash
Cname=$1
cpid=$ (Docker inspect--format "{{. State.pid}} "$CNAME)
Nsenter--target "$CPID"--mount--uts--ipc--net--pid
[Root@docker-node1 ~]#!ca
Cat in.sh
#!/bin/bash
Cname=$1
cpid=$ (Docker inspect--format "{{. State.pid}} "$CNAME)
Nsenter--target "$CPID"--mount--uts--ipc--net--pid
[Root@docker-node1 ~]#

When we look at whether a directory exists, if it exists and enters the directory, a quick cut can use the following example

[Root@docker-node1 ~]# ls/usr/local/
apache-tomcat-7.0.63 bin etc include Lib Libexec share tomcat Tomcat3
apache-tomcat-7.0.63.tar.gz Cmdline-jmxclient-0.10.3.jar Games jdk-7u79-linux-x64.rpm lib64 sbin src tomcat2
[Root@docker-node1 ~]# CD!$
cd/usr/local/
[Root@docker-node1 local]#

Of course, you can also press ESC before pressing. You can quickly reference the previous command

If you do not like to be seen all the historical commands, then history-c can empty the command history, if you do not like to be seen a certain can be history-d number to specify the deletion, but this way to delete, your delete command history of the operation is still in the history

691 Cat in.sh
692 ls/usr/local/
693 cd/usr/local/
694 history
[Root@docker-node1 local]# history-d 693

[Root@docker-node1 local]# History
693 History
694 history-d 693
695 history

Append the current session's command history to the history file-a
Reads all of the included history files, but is not read to the current session,-N
Read History file, save to History list-R
Tell the current history write to the history file and append to the History list-W

Command history save 1000 commands by default, defined in Histsize

[Root@docker-node1 local]# Echo $HISTSIZE
1000
[Root@docker-node1 local]#

. bash_history
[Root@docker-node1 local]# Echo $HISTFILE
/root/.bash_history
[Root@docker-node1 local]#

command history File Save number: Histfilesize

Control command history generation mechanism: Histcontrol
[Root@docker-node1 local]# Echo $HISTCONTROL
Ignoredups: Ignore commands for duplicate records
[Root@docker-node1 local]#

The repetition here is said to be continuous, but not repeated.

Ok. So if I don't want people to see me execute those orders, we need to modify the following:
Modify the ignoredups to Ignorespace

[Root@docker-node1 local]# Histcontrol=ignorespace
[Root@docker-node1 local]# Echo $HISTCONTROL
Ignorespace

Plus space LS before executing the command

[Root@docker-node1 local]# ls
apache-tomcat-7.0.63 bin etc include Lib Libexec share tomcat Tomcat3
apache-tomcat-7.0.63.tar.gz Cmdline-jmxclient-0.10.3.jar Games jdk-7u79-linux-x64.rpm lib64 sbin src tomcat2
[Root@docker-node1 local]# CD Tomcat
[Root@docker-node1 tomcat]#

Looking at history

[Root@docker-node1 tomcat]# History
1 history
2 history-m
3 History-n
4 ls
5 history
6 Histzize
7 Echo $HISTZIZE
8 Echo $HISTsIZE
9 Echo $HISTSIZE
Echo $HISTFILE
One echo $HISTCONTROL
Echo $HISTFILESIZE
Histcontrol=ignorespace
Echo $HISTCONTROL
History
[Root@docker-node1 tomcat]#

that if you want to add the above grid is not recorded, and can go heavy, modify Histcontrol=ignoreboth can

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.