Home > Article > Operation and Maintenance > How to view command history in Linux
Linux can use the history command to view the history command, which can list all typed commands. The commands typed by the user are recorded in a file, which is saved in the home directory of the currently logged in user.
#The operating environment of this article: centos 7 system, thinkpad t480 computer.
In the Linux environment, you can view recently typed commands by pressing the up and down arrow keys. However, this method can only view them one by one. In fact, the system provides a method to view all historical commands.
Enter the following command in the terminal to view all commands:
[root@template ~]# history 1 ifconfig 2 vim /etc/ssh/sshd_config 3 /etc/init.d/sshd restart 4 vim /boot/grub/grub.conf 5 vim /etc/selinux/config 6 vim /etc/sysconfig/network-scripts/ifcfg-eth0 7 rm -rf /etc/udev/rules.d/70-persistent-net.rules 8 useradd vsroot 9 echo -e 'vsroot\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers 10 yum clean all 11 rm -rf /var/log/yum.log 12 rm -rf /var/lib/yum/* 13 rm -rf /root/install.log 14 rm -rf /root/install.log.syslog 15 rm -rf /var/log/anaconda.*
The history command lists all the commands that have been typed. The commands typed by the user will be recorded in the file, which is saved in the current Log in to the user's home directory.
The file name is: .bash_history, this file is a hidden file.
Clearing of historical operation commands:
If you do something bad in the server, you can clear it through the "history -c" command, so that others will not be able to view the history when logging in to the terminal. Operation command.
But this command will not clear the records saved in the file, so you need to manually delete the records in the .bash_profile file.
Free video recommendation: linux video tutorial
The above is the detailed content of How to view command history in Linux. For more information, please follow other related articles on the PHP Chinese website!