I'd like to save the output from running a specific command on the command line. However, after running the command, I am prompted to type in the name of my account to confirm that I would indeed like to run this command.

If I simply use command > file.txt, the prompt itself is saved to the file and I can't type the confirmation. What command can I use to save this output?

  • 1
    nb: you can type the confirmation, you'll just be doing it blind (without having seen the prompt). That said: you'll have to save the prompt to the file or pipe the output to a process that discards that first line (the prompt) and saves the rest to a file. – L. Scott Johnson Jun 4 '19 at 22:57
  • Have you written the command that does the prompting? Interactive prompts are always produced on the standard error stream (for this very reason). If you are able to modify the program, make it prompt on the standard error stream, or submit a bug report to this effect to the author. – Kusalananda Jun 5 '19 at 7:33

You can use tee, which writes both to stdout and a file.

command | tee file.txt

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.