I don't know Why I've downvoted in such manner but still I need an answer

I know that I can easily know my commands history by just running the command history.

But two major consequences raise here:

  1. history -c command will just flush the history
  2. A command with space before will not stored in the history

So if I run the command history -c or a command with space before or other commands such as ^bad^good as @AvinashRaj stated, thus I can't reshow them using the history command.

So is there another way to know all commands ran before?!!

Also the the marked as duplicate sure will not answer my question. It's just a monitoring to terminal and not command history.

  • 2
    What is your question exactly? Do you want to be able to learn your history even when it was flushed, resp. disable the white-space-command-doesn't-go-into-history feature? – Malte Skoruppa Mar 7 '14 at 9:16
  • My question is clear. I want to know the commands history whatever done – Maythux Mar 7 '14 at 9:17
  • So you want to have your history show the 'history -c' command when issued and also the commands that started with a space? – Noosrep Mar 7 '14 at 9:32
  • 1
    sudo !! command also wouldn't be stored in the history. – Avinash Raj Mar 7 '14 at 9:48
  • @TimothyPersoon Yes – Maythux Mar 7 '14 at 9:52

The bash terminal commands history for a user is stored in $HOME/.bash_history file. The commands used in the tty session will be written to the .bash_history file when the tty session is terminated; but running history -c command will prevent them from being appended in the history file. What history command does is it displays the contents of the $HOME/.bash_history. (You can also check and/or edit the file with text editors, say with nano $HOME/.bash_history.)

"A command with a space before it won't be stored.., !! or duplicate commands won't be stored, etc."

You can change the settings according to your needs by making changed in $HOME/.bashrc file. This post explains how: Get bash history to remember only the commands run with space prefixed!.

And in this file you may find lines like:

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)

HISTSIZE is the number of commands to remember in the command history. The default value is 500.

HISTFILESIZE is maximum number of lines contained in the history file. When this variable is assigned a value, the history file is truncated, if necessary, by removing the oldest entries, to contain no more than that number of lines. The default value is 500. The history file is also truncated to this size after writing it when an interactive shell exits.

So, to summarize history -c just clears the running tty session's history and the previous commands should still be accessible with history command provided the older commands are not truncated as per the HISTFILESIZE <= max_lines constraint.

  • 1
    That's good friend – Maythux Mar 8 '14 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.