Advertisement
Tech

Linux Syntax Commands: The history Command

The Linux operating system has thousands of commands of which you will use many. Knowing what commands you’ve used in recent history can help you administer a desktop or server. The “history” command is a tool that will show you what commands you have used when your memory fails.

By jlwallen
Desk Tech
Reading time 3 min read
Word count 507
Linux Computing Linux commands
Linux Syntax Commands: The history Command
Advertisement
Quick Take

The Linux operating system has thousands of commands of which you will use many. Knowing what commands you’ve used in recent history can help you administer a desktop or server. The “history” command is a tool that will show you what commands you have used when your memory fails.

On this page

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.)

Basic Usage

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:

Advertisement

485 su

486 cd Desktop/

Advertisement

487 ls

488 sudo mv wireframe-DR16.tar.gz /usr/share/e16/themes

Advertisement

489 cd /usr/share/e16/themes/

490 sudo mkdir WIRE

Advertisement

491 sudo mv wireframe-DR16.tar.gz WIRE

492 cd WIRE/

Advertisement

493 sudo tar xvzf wireframe-DR16.tar.gz

494 exit

Advertisement

495 cd .e16/menus/

496 nano user_apps.menu

Advertisement

497 exit

498 gnome-control-center

Advertisement

499 kilalll -9 thunderbird

500 exit

Advertisement

501 history

502 man history

Advertisement

503 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:

Advertisement

history | less

Which would allow you to scroll one page at a time through the history list.

Advertisement

More Usage

Here are some other ways to use history.

history -c: Clears the history buffer.

Advertisement

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.

Final Thoughts

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.

This post is part of the series: Keeping Your Linux Machine Clean

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.

  1. Keep Your Linux Box Clean with These Tools
  2. Linux Command Line: cruft-remover
  3. Linux Command Line: history
  4. Linux Command Line: rm
  5. Linux Command Line: locate
Keep Exploring

More from Tech

Filed under
Linux Computing
More topics
Linux commands
Advertisement