![](/img/trans.png)
[英]Difference between “command > log.txt” and “command 1>& log.txt” in Linux command shell?
[英]Is there a Linux equivalent to Windows >log.txt for logging command output to a file?
字符>(或>>)可与Windows中的命令一起使用,以将命令结果记录到文件中。 Linux有此功能吗? 你怎么做呢?
示例:$ find /?>find.txt
此命令将在当前目录中创建一个名为find.txt的文件。 键入命令后,此文件将包含在术语窗口中找到的内容:
Searches for a text string in a file or files.
FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]
/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
/OFF[LINE] Do not skip files with offline attribute set.
"string" Specifies the text string to find.
[drive:][path]filename
Specifies a file or files to search.
If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
它在Linux中的工作方式相同。 >
将覆盖输出文件, >>
将追加到该文件。 有些程序会将错误输出到STDERR,您可以使用2>
捕获错误。 有时,您会看到使用2>&1
将STDERR重定向到与STDOUT相同的位置,以便可以立即捕获所有输出。
是的,看起来也一样:
find --help > find.txt # write to a new file
find --help >> find.txt # append to the file
它的工作原理相同。
find / > log.txt
可以使用tee命令找到额外的奖励,这将保存到文件中并同时显示输出。
find / | tee log.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.