In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the "shell under the time command output detailed explanation", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "shell under the time" command output detailed explanation "bar!
Preface
I believe we all know that time under bash is a very useful command, which can time the execution of a script or a program, which is usually very convenient when roughly comparing the efficiency of program execution. However, you will find that the time text output by the time command cannot be simply redirected, such as redirecting to a text file, which can only be displayed on the screen, which is very inconvenient for non-interactive timing.
For example:
$time find. -name "mysql.sh" > 1.txtreal 0m0.081suser 0m0.060ssys 0m0.020s $time find. -name "mysql.sh" 2 > 2.txt./work186/sms/bin/mysql.sh./work186/sms/src/scripts/mysql.sh./work186/sms/src/scripts1/mysql.sh./work186/sms1/bin/mysql.sh./work186/sms1/src/scripts/mysql.sh./temp/sms/bin/mysql.sh./temp/sms/src/scripts/mysql.shreal 0m0.068suser 0m0.040ssys 0m0.030s
Through the above attempt, it is found that the output information of time can not be redirected to the file. Why? Because time is the keyword of shell, shell does special treatment. It treats the command line after the time command as a whole. When redirecting, it is actually for the following command, and the output of the time command itself will not be redirected.
The keyword time sets a flag until the command (find) command is executed before the timing information is printed to stderr. The time keyword requires the entire command and pipeline, as well as related redirects, to be advanced. This is why simple redirection doesn't work for time. This is defined by the Bash syntax. Redirection after command is part of command for time.
Note: output of time command to standard error (stderr)
When the time command is executed, the command runs at the next level shell of the current shell (that is, the shell executed by the time command), and the output of the time itself is at the stderr of the current shell. Redirecting as shown above only causes command's stdout to be redirected to a text file and does not output the output of the time itself.
The first solution is to put the time command and the command line to be executed in a block of shell code, that is, a pair of curly braces, paying attention to the use of spaces and semicolons.
${time find. -name "mysql.sh";} 2 > 2.txt.Universe work186Universe SmsUnix bind mysql.sh.Zetwork186UniSmsUniSrcUniptsScriptsGrease mysql.sh.Simplwork186UniSsmsUniScripts1UseMyql.sh.UnitedScripts1UseMyql.sh.Uniwork186UnidirectionSms1binUniSmql.sh.tempscarsmsql.sh.tempthessmsql.sh. $cat 2.txtreal 0m0.068suser 0m0.030ssys 0m0.040s
The first attempt was successful, and to sum up, {time command-line;} 2 > file pay attention to the use of delimiters.
Another way is to use sub-Shell.
As follows:
(time find. -name "mysql.sh") 2 > 2.txt.Universe work186 > 2.txt.Universe ScriptsCharger mysql.sh.scarwork186UniSsmsUniScriptsStemql.sh.Simplework186UniSsmsUniScripts1UseMyql.sh.UnitedScripts186Unidirectionsms1binSimpMyql.sh.andwork186apsms1hand srcscriptsmysql.sh.
The second approach has also been tried successfully, which can be summed up as (time command-line) 2 > file where time clings to parentheses (alternatively, there is no need to end the command line with a semicolon. Of course, it is best to use the first way, after all, starting a sub-shell takes up more resources.
Thank you for your reading, the above is the content of the "detailed explanation of the output of the time command under shell". After the study of this article, I believe you have a deeper understanding of the detailed explanation of the output of the time command under shell, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.