将管道输入转储到文件的简单方法是使用 >
符号。在 Linux 中,可以使用以下命令将命令的输出转储到文件中:
command > file
其中,command
是要执行的命令,file
是要将输出转储到的文件名。例如,如果要将 ls
命令的输出转储到名为 output.txt
的文件中,可以使用以下命令:
ls > output.txt
这将把 ls
命令的输出写入到 output.txt
文件中,如果文件已经存在,则会被覆盖。如果要将输出追加到文件中,而不是覆盖它,则可以使用 >>
符号:
command >> file
例如,要将 ls
命令的输出追加到 output.txt
文件中,可以使用以下命令:
ls >> output.txt
这将把 ls
命令的输出追加到 output.txt
文件的末尾。
领取专属 10元无门槛券
手把手带您无忧上云