Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Bash's command history is great, especially it is useful when adding the history -a command to the COMMAND_PROMPT.

However, I'm wondering if there is a way to log the commands to a file as soon as the Return key is pressed, e.g. before starting the command and not on completion of the command (using the COMMAND_PROMPT option would save the command once the prompt is there again).

I read about auditing programs like snoopy and session recorder like script but I thought they're already too complex for the simple question I have. I guess that deactivating that script logs all the output of the command would lead already in the right direction but isn't there a quicker way to solve that probelm?

Thanks, Jon

share|improve this question

migrated from Aug 21 '10 at 20:44

This question came from our site for professional and enthusiast programmers.

@Jon there is no COMMAND_PROMPT. i think you mean PROMPT_COMMAND. – lesmana Aug 21 '10 at 0:36
related:… – lesmana Aug 21 '10 at 1:05

The DEBUG trap is executed before each command. You could set up a trap and in that do your logging.

share|improve this answer
Excellent. Thank you very much. There is a little bit of fine tuning still necessary but it looks very promising. – Jon Jun 7 '10 at 21:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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