cat
命令用于打印文本文件的文件内容。至少,大多数 Linux 用户都是这么做的,而且没有什么问题。
cat
实际上代表 “连接(concatenate)”,创建它是为了 合并文本文件。但只要有一个参数,它就会打印文件内容。因此,它是用户在终端中读取文件而无需任何其他选项的首选。
在 Linux 中使用 cat 命令
要使用 cat
命令,你必须遵循给定的命令语法:
cat [options] Filename(s)
这里:
[options]
用于修改cat
命令的默认行为,例如使用-n
选项获取每行的数字。Filename
是你输入要使用的文件的文件名的位置。
为了简单起见,我将在本指南中使用名为 Haruki.txt
的文本文件,其中包含以下文本行:
Hear the Wind Sing (1979)
Pinball, 1973 (1980)
A Wild Sheep Chase (1982)
Hard-Boiled Wonderland and the End of the World (1985)
Norwegian Wood (1987)
Dance Dance Dance (1990)
South of the Border, West of the Sun (1992)
The Wind-Up Bird Chronicle (1994)
Sputnik Sweetheart (1999)
Kafka on the Shore (2002)
After Dark (2004)
1Q84 (2009-2010)
Colorless Tsukuru Tazaki and His Years of Pilgrimage (2013)
Men Without Women (2014)
Killing Commendatore (2017)
那么,在没有任何选项的情况下使用时,输出会是什么? 好吧,让我们看一下:
cat Haruki.txt