Saving output to files
Linux & the command line Lesson 6 1:54 English narration · English + 中文 subtitles burned in
Chapters
Transcript
Normally a command's output appears on screen.
通常一条命令的输出会出现在屏幕上。
Add an arrow and a filename and it does not — and the first time, that looks like nothing happened.
加上一个箭头和一个文件名,它就不出现了—— 而第一次遇到时,那看起来像是什么都没发生。
It did: the text went somewhere else, into the file you named.
其实发生了:那些文字去了别的地方,去了你指定的那个文件里。
Read it back with cat and there it is.
用 cat 读回来,它就在那儿。
A silent command here is the successful one.
在这里,一条"没声音"的命令才是成功的那一条。
There are two arrows and they do different things.
有两种箭头,它们做的事不一样。
One arrow replaces the file's contents.
一个箭头替换文件的内容。
Two arrows append — it adds to the end and keeps what was there.
两个箭头是追加——它加在末尾,并保留原来就有的东西。
Look at the two results: on the right, both lines.
看这两个结果:右边,两行都在。
On the left, only the second, because the second command threw the first line away before writing.
左边,只有第二行, 因为第二条命令在写入之前把第一行扔掉了。
That matters most when the file already had something you wanted.
当那个文件里本来有你想要的东西时,这一点最要紧。
One arrow onto a file that exists erases it first, then writes.
一个箭头指向一个已经存在的文件,会先把它清空,然后再写。
Two lines of poem, one short command, and the poem is gone.
两行诗,一条短命令,那首诗就没了。
There is no undo, no more than with r m — so when you mean "add", type two arrows.
没有撤销,和 rm 一样没有—— 所以当你的意思是"添加"时,就打两个箭头。
Three things this buys you.
这给你带来三样东西。
You can keep a result instead of watching it scroll away.
你可以把一个结果留下来,而不是看着它从屏幕上滚走。
You can build a file out of what commands produce — a list of filenames, a report.
你可以用命令产生的东西去构建一个文件——一份文件名清单,一份报告。
And with two arrows you can append to a log, one line at a time, over days.
而用两个箭头,你可以往一个日志里追加,一次一行,持续好些天。
Next lesson takes it further and sends output straight into another command.
下一课会更进一步,把输出直接送进另一条命令里。
Four things to take with you.
带走四点。
One: one arrow sends a command's output into a file.
第一:一个箭头把命令的输出送进一个文件。
Two: nothing prints, and that is correct.
第二:屏幕上什么都不打印,而这是对的。
Three: one arrow REPLACES the file, erasing it first.
第三:一个箭头会替换那个文件,先把它清空。
Four: two arrows append to the end.
第四:两个箭头是追加到末尾。
Now type the tasks into the terminal below.
现在把下面那些题目敲进终端里。