- slide 1 of 4
What "history" does
So far in the Linux Command Line series we have covered a lot of ground. In just a short time you have read about more commands than you can probably remember. After administering a Linux machine you might have trouble remembering which commands have been run on a machine. Or, as an administrator, you might want to know what commands each user has issued. That is where history comes in. The bash shell keeps a list of the commands issued. The number of commands retained is quite large. This number, naturally, can be cleared. The history command can also be configured to only retain a set amount of commands. By setting the number of commands history remember you can avoid certain security issues. Say, for instance, you accidentally leave your root user logged in and you have just issued a specific iptables rule chain. A user could come by, issue the history command, and know what the iptables rule is (thereby having a foot in the door of your server.)
- slide 2 of 4
The history command is issued from a terminal emulator such as aterm, eter, or xterm. If you issue the command without any arguments you will see something like this:
486 cd Desktop/
488 sudo mv wireframe-DR16.tar.gz /usr/share/e16/themes
489 cd /usr/share/e16/themes/
490 sudo mkdir WIRE
491 sudo mv wireframe-DR16.tar.gz WIRE
492 cd WIRE/
493 sudo tar xvzf wireframe-DR16.tar.gz
495 cd .e16/menus/
496 nano user_apps.menu
499 kilalll -9 thunderbird
502 man history
This would be the last 19 commands issued from my terminal. To be able to go through the entire list pipe, the history command through the less command enter:
history | less
Which would allow you to scroll one page at a time through the history list.
- slide 3 of 4
Here are some other ways to use history.
history -c: Clears the history buffer.
history -a: Append the new history lines to the ~/.bash_history file. The new lines are those that have been entered since the newest bash session started.
history -w: Write out the current history to the ~/.bash_history file.
The above list is really the most useful of the arguments.
- slide 4 of 4
Keeping tabs on your history file can, in certain circumstances, mean the difference between a secure system and an insecure system. Making a habit of clearing your bash history can keep prying eyes from knowing what commands you have issued. So keep that history cleared on a regular basis.
Linux Command Line: history
If you have used a PC for any length of time you know that a hard drive can very quickly become cluttered with files, remains of uninstalled applications, and disorganized files and directories. In this Brighthub series you will learn the tools to keep your Linux system clean.