Output from the recording terminal to a text file in Centos

Source: Internet
Author: User
1. Save the command running result to the File: Use & gt; to turn the output to the file. for example, the & gt; command in outputs indicates that the output is redirected to the specified file, if the file already exists, it will be written again, and the original content of the file will not be retained & gt;

1. Save the command running result to the file: Use> to turn the output to the file.
Example:
$ Ls> ls.txt # or ls --> ls.txt save the lscommand running result to the ls.txt file.

Note:> it refers to turning the output to the specified file. if the file already exists, it will be written again, and the original content of the file will not be retained.
> The output is appended to the end of the file. The original content of the file is retained.

2. record the information to the file while outputting the information: tee command
To explain the role of tee:
"Read from standard input and write to standard output and files", which reads content from standard input and writes it to standard output and files.

Parameter:-a, -- append, "append to the given FILEs, do not overwrite", appended to the given file, instead of overwriting it

Example:
$ Ls | tee ls.txt scripts will display the lscommand execution result on the scripts and output the execution result to the ls.txt file.
$ Ls | tee-a ls.txt contains the original content in the ls.txt file, and returns the execution result of the lscommand to the end of the ls.txt file.

3. output of multiple commands must be recorded: script commands
Script is a powerful command that records all output from the terminal to the corresponding file.
Example:
1. $ script
Script. started, file is typescript
2. $ ls
...... Content omitted
3. $ exit
Exit
Script. done, file is typescript
4. $ cat typescript # The green part above will be displayed again:

Note:
1. the file name is not specified when script is started. it is automatically recorded in the next file named typescript in the current directory. You can also use the-a parameter to specify the file name.
Example:
$ Script.-a example.txt # The Output Content of the terminal is recorded in the example.txt file.
2. use exit when exiting the script. In fact, the script starts a shell.


Related Article

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.