# # # Bash in the History command in the Shell
----------
In daily operations, we often use the history command to check the historical commands executed on this machine, or at what time the commands are executed. The history command does not show the time by default and we can set it.
----------
-Displays the commands that have been executed
Simply tap the keyboard and enter a word: history. Or the his +table key bash auto-complete command, the terminal will display the line number and the corresponding command.
> [[email Protected] ~]$ history
1 exit
2 DFDFD
3 Su-
4 vim. BASHRC
5 Vi. BASHRC
6 source. Bash
7 source. BASHRC
8 VI/ETC/BASHRC
9 Vi. BASHRC
Ten Su-
----------
-Displays the timestamp performed by the history command
We need to build the file in the/etc/profile.d/directory: history_config.sh.
The content is: Export histtimeformat= '%F%T '
which
%F equivalent to%Y-%m-%d
%T equivalent to (%H:%M:%s)
Configured in the global configuration file, which allows all users to be configured to take effect. Of course you can configure it in a specific user's profile.
----------
-Set the number of history commands to save and display
The history commands in the Linux system are saved by default in the ~/.bash_history file, and we can set histfilesize and histsize to control the number of history commands saved and the number displayed on the screen respectively.
In the/etc/profile.d/history_config.sh file,
Add to:
Export histfilesize=1024
Export histsize=100
If set to 0, the history save is disabled.
After setting, the Source/etc/profile makes the setting take effect.
For example:
> [[email protected] ~]$ Source/etc/profile
> [[email Protected] ~]$ history
712 2015-08-08 12:33:55 df-h/Home
713 2015-08-08 12:33:55 du
714 2015-08-08 12:33:55 du/h
715 2015-08-08 12:33:55 Du-sh
716 2015-08-08 12:33:55 du-sh/home/doctor/
717 2015-08-08 12:33:55 quot
718 2015-08-08 12:33:55 Quota
719 2015-08-08 12:33:55 Su-
720 2015-08-08 12:33:55 Source/etc/profile
721 2015-08-08 12:33:55 Android Update SDK
722 2015-08-08 12:33:55 TNS
723 2015-08-08 12:33:55 Su-
724 2015-08-08 12:33:55 Android
725 2015-08-08 12:33:55 Source/etc/profile
726 2015-08-08 12:33:55 ADB
727 2015-08-08 12:33:55 Source/etc/profile
728 2015-08-08 12:33:55 ADB
729 2015-08-08 12:33:55 Su-
730 2015-08-08 12:33:55 Source/etc/profile
731 2015-08-08 12:33:55 Android SDK update
732 2015-08-08 12:33:55 Android SDK
733 2015-08-08 12:33:55 NPM install-g nativescript
734 2015-08-08 12:33:55 npm install nativescript-g--unsafe-perm
735 2015-08-08 12:33:55 Source/etc/profile
736 2015-08-08 12:33:55 NPM Install Nativescript-g
737 2015-08-08 12:33:55 Source/etc/profile
738 2015-08-08 12:33:55 ADB
739 2015-08-08 12:33:55 Android
740 2015-08-08 12:33:55 NPM install-g nativescript
741 2015-08-08 12:33:55 TNS Hello
742 2015-08-08 12:33:55 ADB
743 2015-08-08 12:33:55 which ADB
744 2015-08-08 12:33:55 Android SDK update
745 2015-08-08 12:33:55 Android Update SDK
746 2015-08-08 12:33:55 Su-
747 2015-08-08 12:33:55 NPM install-g nativescript
748 2015-08-08 12:33:55 CD documents/
749 2015-08-08 12:33:55 TNS Create Hello-world
2015-08-08 12:33:55 CD hello-world/
751 2015-08-08 12:33:55 LL
752 2015-08-08 12:33:55 Tree
753 2015-08-08 12:33:55 TNS Platform Add Android
754 2015-08-08 12:33:55 LL
755 2015-08-08 12:33:55 TNS run Android--emulator
756 2015-08-08 12:33:55 Source/etc/profile
757 2015-08-08 12:33:55 Android SDK
758 2015-08-08 12:33:55 Less/etc/ssh/sshd_config
759 2015-08-08 12:33:55 Su-
760 2015-08-08 12:33:55 Service sshd Status
761 2015-08-08 12:33:55 who
762 2015-08-08 12:33:55 who
763 2015-08-08 12:33:55 PWD;WHO;CD ... Pwd
764 2015-08-08 12:33:55 PWD;WHO;CD ... Pwd
765 2015-08-08 12:33:55 who
766 2015-08-08 12:33:55 who am I
767 2015-08-08 12:33:55 Service sshd Status
768 2015-08-08 12:33:55 ssh localhost
769 2015-08-08 12:33:55 pwd;
770 2015-08-08 12:33:55 LL
771 2015-08-08 12:33:55 who
772 2015-08-08 12:33:55 who am I
773 2015-08-08 12:33:55 Date
774 2015-08-08 12:33:55 Su-
775 2015-08-08 11:51:57 History
776 2015-08-08 12:33:55 History
777 2015-08-08 12:33:55 Su-
778 2015-08-08 11:25:25 History
779 2015-08-08 11:26:07 Echo $HISTTIMEFORMAT
780 2015-08-08 11:42:45 History
781 2015-08-08 11:44:00 Reset
782 2015-08-08 11:44:04 History
783 2015-08-08 11:47:06 Export Histtimeformat = '%F%T '
784 2015-08-08 11:47:14 Export histtimeformat= '%F%T '
785 2015-08-08 11:47:17 History
786 2015-08-08 11:47:58 LL
787 2015-08-08 11:48:02 History
788 2015-08-08 11:48:24 Reset
789 2015-08-08 11:48:28 History
790 2015-08-08 11:49:54 CD.
791 2015-08-08 11:49:55 pwd
792 2015-08-08 11:49:58 Reset
793 2015-08-08 11:50:00 History
794 2015-08-08 11:52:37 LL
795 2015-08-08 11:52:38 History
796 2015-08-08 11:52:52 Less/etc/profile
797 2015-08-08 11:57:15 Su-
798 2015-08-08 11:57:42 LL
799 2015-08-08 11:57:43 Clear
2015-08-08 11:57:47 History
801 2015-08-08 11:58:28 LESS/ETC/BASHRC
802 2015-08-08 12:03:42 Less/etc/profile
803 2015-08-08 12:04:10 LESS/ETC/BASHRC
804 2015-08-08 12:05:15 Su-
805 2015-08-08 12:06:51 LL
806 2015-08-08 12:06:53 History
807 2015-08-08 12:33:57 pwd
808 2015-08-08 12:33:59 LL
809 2015-08-08 12:34:00 History
810 2015-08-08 12:35:28 Source/etc/profile
811 2015-08-08 12:36:23 History
Only 100 rows are displayed.
----------
-Query the commands executed by a specific user
Bash in the user root directory, the user's command history will be saved in the ~/.bash_history file, we can know the user's command history.
----------
-Delete history command record
> [[email protected] ~]$ history-c
>
[Email protected] ~]$ history
1 2015-08-08 12:22:56 History
[Email protected] ~]$
----------
-Query the command history with the grep command
> [[email protected] ~]$ history | grep pwd
>
3 2015-08-08 12:23:57 pwd
4 2015-08-08 12:24:04 History | grep pwd
[Email protected] ~]$
----------
-Query for commands that have just been executed recently
We can use the up and down arrow keyboards on the keyboard to scroll through the records. You can also use CTRL + R to enter a partial command lookup (prompting)
----------
Copyright NOTICE: This article for Bo Master original article, without BO Master permission cannot reprint [http://blog.csdn.net/doctor_who2004].
The history command in the Bash Shell