0

An application with stderr is being run using the time command. I want the output of the application to be redirected to /dev/null, the stderr redirected to a log, and the timing redirected to a log.

executing the command:

time cmd args >/dev/null 2>log

redirects the cmd, but not the time command with the timings.

Dov
  • 8,000
  • 8
  • 46
  • 75
  • A search on SO for '`[bash] time output`' shows many plausible duplicates, including [`time` output redirection](http://stackoverflow.com/questions/27434522/time-output-redirection), [Bash `time` output processing](http://stackoverflow.com/questions/8308400/bash-time-output-processing) (the oldest of these three), and [Is there a way to redirect `time` output to file in Linux?](http://stackoverflow.com/questions/13356628/is-there-a-way-to-redirect-time-output-to-file-in-linux). – Jonathan Leffler Mar 28 '15 at 21:11
  • @JonathanLeffler Any particular reason you are not nominating to close as a duplicate of one of them? – tripleee Mar 29 '15 at 08:30
  • Also http://mywiki.wooledge.org/BashFAQ/032 and [perhaps more duplicates](https://www.google.com/search?q=http://mywiki.wooledge.org/BashFAQ/032+site:stackoverflow.com). – tripleee Mar 29 '15 at 08:33
  • 1
    @tripleee: mainly that I am not convinced I've got a canonical duplicate. The answer for the earliest one of the three I list is not very good. There are probably other better duplicates out there. I need to look at what you found too. I live in hope someone else will do the hard work of finding a really good duplicate. As a wielder of Mjölnir, I have to be very careful. – Jonathan Leffler Mar 29 '15 at 14:09

1 Answers1

4

If your goal is to capture the time output to the log file, then use:

{ time seq 1000 >/dev/null; } 2>log
John1024
  • 109,961
  • 14
  • 137
  • 171
  • 1
    Excellent use of curly braces to redirect output from a code block. If you want to know more about curly braces, then check out http://www.tldp.org/LDP/abs/html/special-chars.html#CODEBLOCKREF – Keith Shaw Mar 09 '17 at 01:52