The output result of the DD command cannot be redirected to a file.

Source: Internet
Author: User
ArticleDirectory
    • Solve the redirection problem of Time Command output information

Take time as an example:

Solve the redirection problem of Time Command output information

The output information of the Time Command is printed on the standard error output, Let's verify it through a simple attempt.

[Root @ web186 root] #Time find.-Name "mysql. Sh"> 1.txt 

Real 0m0. 081 s
User 0m0. 060 s
Sys 0m0. 020 s
[Root @ web186 root] #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

Real 0m0. 068 s
User 0m0. 040 s
Sys 0m0. 030 s

Through the above attempt, I found that I could not redirect the time output to the file. Why? Because time is the shell keyword, shell performs special processing, it will process the command line following the time command as a whole. During redirection, in fact, the output of the time command is not redirected. What should we do now? There are two solutions available on the Internet [2, 3]. Let's try them one by one.

The first solution is to place the Time Command and the command line to be executed in a shellCodeBlock, that is, the use of spaces and semicolons. 
[Root @ web186 root] #{Time find.-Name "mysql. Sh"} 2> 2.txt

It seems to have succeeded. Slow. check whether it is correct. 
[Root @ web186 root] #Cat 2.txt
-Bash: {time: Command not found

Originally, bash processed {time as a whole, and added spaces before and after. 
[Root @ web186 root] #{Time find.-Name "mysql. Sh"} 2> 2.txt 
>CTRL + c

This bash thought that the command was not completed and the semicolon was missing. Because bash considers the following} as a parameter of the find command. 
[Root @ web186 root] #{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. Sh
[Root @ web186 root] #Cat 2.txt 

Real 0m0. 068 s
User 0m0. 030 s
Sys 0m0. 040 s

The first method is successful. In summary, {time command-line;} 2> file must be used as the delimiter.

Another method is to use a sub-shell, as shown below:

[Root @ web186 root] #(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. Sh
[Root @ web186 root] #Cat 2.txt

Real 0m0. 083 s
User 0m0. 040 s
Sys 0m0. 020 s
[Root @ web186 root] #

The second method also succeeded. In summary, it is (Time command-line) 2> file. Here, time is closely related to parentheses (which is also acceptable. The command line does not end with a semicolon. Of course, it is best to use the first method. After all, starting a sub-shell requires more resources.

 

For dd commands. Same as the time command, the DD command includes the time command.

Therefore, dd If =/dev/Zero of =/mnt/test BS = 1 k count = 100> output.txt

You cannot save the time and speed of the command output to output.txt. This is because the output of the DD command is to the standard error output.

You must use dd If =/dev/Zero of =/mnt/test BS = 1 k count = 100 2> output.txt.

From: http://dylan602.blog.163.com/blog/static/167974276201172121823753/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.