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.