预计阅读本页时间:-
I/O Redirection
cat is short for "catenate," i.e., link together. It accepts multiple filename arguments and copies them to the standard output. But let's pretend, for now, that cat and other utilities don't accept filename arguments and accept only standard input. As we said above, the shell lets you redirect standard input so that it comes from a file. The notation command < filename does this; it sets things up so that command takes standard input from a file instead of from a terminal.
For example, if you have a file called cheshire that contains some text, then cat < cheshire will print cheshire's contents out onto your terminal. sort < cheshire will sort the lines in the cheshire file and print the result on your terminal (remember: we're pretending that these utilities don't take filename arguments).
广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元
Similarly, command > filename causes the command's standard output to be redirected to the named file. The classic "canonical" example of this is date > now: the date command prints the current date and time on the standard output; the previous command saves it in a file called now.
Input and output redirectors can be combined. For example: the cp command is normally used to copy files; if for some reason it didn't exist or was broken, you could use cat in this way:
$ cat <
file1
>
file2
This would be similar to cp file1 file2.