Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

I know that there is a way to write bash shell outputs to a file. However, I want to know what commands have been executed by an application as some of these executions are not outputted as a shell output.

So, is there a way to write commands, including outputs, that were executed to a file?

share|improve this question

if you run a bash script by calling it with:

bash -x

you will see both the commands and the output give by the commands run.

share|improve this answer

If you execute your script with -x (e.g. bash -x <script>) you will see every output. If you want to run it normally without seeing the output (but redirect it to a file too), you can do bash -x <script> 2>/dev/null

Normally the -x bit prints to stderr (2) and not stdout (1).

You could set -x from within the script where you want to (and set +x when not) and redirect all STDERR to a file like above (scriptname.bash 2>coolfile.txt).

Much beyond that, you'll need to resort to perl or python.

share|improve this answer

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.