We're an ISO27001:2013 Certified Supplier

You probably know about the command line history: typing, for example, an up-arrow will recall the last command typed, and the history command will list as many commands as have been saved.

But suppose you don’t want a particular command to appear in the history? You may want to give a password on the command line and hide that from the history. Just start the command with a space:

$ mycommand --user me --password secret # goes into the history

$  mycommand --user me --password secret # doesn't go into the history

Gotchas

  • Be aware that your command may still be seen by other users using the ps command or exploring the /proc filesystem.
  • As pointed out in the comments , the environment variable HISTCONTROL needs to be set to ignorespace or ignoreboth for this tip to work. That appears to be the default in most Linux distributions, but BSD seems to have different defaults and a local sysadmin might have changed the global profile.

Despite the caveats, the above can be useful for all sorts of things. Next time you’re embarrassed at needing to look at the man page for ls and don’t want anyone else to see that in the history, just precede man with a space…

Could this Linux Tip be improved? Let us know in the comments below.

2 thoughts on “Linux Tips: Keeping Commands out of Command Line History”

  1. That relies on a shell option being set correctly. The environment variable HISTCONTROL needs to have the value ‘ignorespace’ or ‘ignoreboth’ – this is the default in most (all?) Linux distros, but BSD seems to have different defaults and a local sysadmin might have changed the global profile.

Leave a Reply

Your email address will not be published. Required fields are marked *

Secure. Reliable. Scalable.

If that doesn't describe your current Linux systems, check out our FREE Linux Survival Guide to help you get your systems up to scratch today!

  • This field is for validation purposes and should be left unchanged.