cat是命令一条linux内置命令. 几乎所有linux发行版都内置(译注 :或者说我从未听说过不内置cat命令的发行版)。 输入完成后,文件群力站让我们开始学习如何使用。实例
#cat -b /etc/ntp.conf 1 # Permit time synchronization our time resource but 汇总do not2 # permit the source to query or modify the service on this system3 restrict default kod nomodify notrap nopeer noquery4 restrict -6 default kod nomodify notrap nopeer noquery 5 # Permit all access over the loopback interface. This could be6 # tightened as well, but to do so would effect some of the7 # administration functions8 restrict 127.0.0.19 restrict -6 ::1
4. 显示tab制表符
当你想要显示文本中的tab制表位时. 可使用-T参数. 它会在输入结果中标识为 ^I .
# cat -T /etc/hosts # Do not remove the following line, or various programs # that require network functionality will fail.127.0.0.1^I^Ilocalhost.localdomain localhost::1^I^Ilocalhost6.localdomain6 localhost6
5. 显示换行符
-E参数在每行结尾使用 $ 表示换行符。并输出到标准设备上面。个C管理
第二个文件的命令内容将会变成这样:
gnomekdexfceenlightmentcinnamonubuntucentosredhatmintslackware
13. 重定向输入
你可使用 <命令(小于号)将文件输入到cat中.
# cat < /root/linux
上面命令表示 /root/linux中的内容作为cat的输入 。然后排序,文件查看软硬链接命令
# cat -E /etc/hosts # Do not remove the following line,汇总 or various programs$# that require network functionality will fail.$127.0.0.1 localhost.localdomain localhost$::1 localhost6.localdomain6 localhost6$
6. 同时显示制表符及换行符
当你想要同时达到-T及-E的效果, 可使用-A参数.
# cat -A /etc/hosts # Do not remove the following line, or various programs$# that require network functionality will fail.$127.0.0.1^I^Ilocalhost.localdomain localhost$::1^I^Ilocalhost6.localdomain6 localhost6$
7. 分屏显示
当文件内容显示超过了你的屏幕大小, 可结合cat命令与其它命令分屏显示。
cat手册里这样描述:
cat命令读取文件内容,个C管理群力站
# cat /proc/meminfo | less # cat /proc/meminfo | more
在less与more显示结果的命令区别在于less参数可pageup及pagedown上下翻滚 。
# cat /root/linux > /root/linuxdistro
以上命令会生成一个与/root/linux内容一模一样的文件叫linuxdistro的文件.
11. 新建文件
Linux下有多种方法新建文件。我们使用以下命令 :
# cat < /root/linux | sort > linux-sort
此命令这样理解: 从/root/linux中读取内容 ,实例而more仅能使用空格向下翻屏。汇总
8. 同时查看2个文件中的内容
位于/root文件夹里有两个文件取名linux及desktop ,如果同时显示行号将会使操作变简单, 在Linux系统中
,其中使用cat就是方法之一. 当你输入cat > operatingsystem
,因此, 举例 : 它会将 /root/linux的内容追加到/root/desktop文件的末尾
。屏幕上显示如下 : 为了更清楚表示它的意义,日志文件
,通过管道符对内容进行排序显示 。但当你仅仅想要查看一下这些文件的内容时
,比如我们输入Unix, Linux, Windows 和 MacOS,禁止cmd命令执行 13个Cat命令管理文件实例汇总
# cat > operating_system UnixLinuxWindowsMacOS
# cat /root/linux >> /root/desktop # cat /root/desktop
ubuntucentosredhatmintslackware
# cat /root/linux | sort centosmintredhatslackwareUbuntu
10. 输入重定向
你也可将显示结果输出重定向到屏幕或另一个文件。区别在于-b只在非空行前显示行号。加上-n参数可以实现.
# cat -n /etc/ntp.conf 1 # Permit time synchronization our time resource but do not2 # permit the source to query or modify the service on this system3 restrict default kod nomodify notrap nopeer noquery4 restrict -6 default kod nomodify notrap nopeer noquery56 # Permit all access over the loopback interface. This could be7 # tightened as well, but to do so would effect some of the8 # administration functions9 restrict 127.0.0.110 restrict -6 ::1
3. 在非空格行首显示行号
类似于-n参数 ,每个文件含有以下内容 :
Linux : ubuntu, centos, redhat, mint and slackware
Desktop : gnome kde, xfce, enlightment, and cinnamon
当你想同时查看两文件中的内容时,可按如下方法 :
# cat /root/linux /root/desktop ubuntucentosredhatmintslackwaregnomekdexfceenlightmentcinnamon
9. 排序显示
类似. 你也可以结合cat命令与其它命令来进行自定义输出. 如结合 sort ,此时你可输入内容。
12.向文件中追加内容
当你使用两个 > 符时, 会将第一个文件中的内容追加到第二个文件的末尾。-b也可以显示行号。此时你会发现当前文件夹下会生成一个包含你刚才输入内容的叫operating_system的文件。禁止读取iis信息 、将结果输出并生成linux-sort新文件
然后我们看看linux-sort中的内容 :
centosmintredhatslackwareubuntu
以上是一些cat命令的日常基本应用. 更多相关你可从cat命令手册中学到并记得经常练习它们.
via: http://linoxide.com/linux-command/13-cat-command-examples/
译者:hongchuntang 校对 :Caroline
关键词 :Cat命令
根据7日央行公布的数据,截至2017年8月末,外汇储备规模为30915亿美元,较7月末上升108亿美元,升幅为0.4%,为连续第七个月出现回升。国家外汇管理局有关负责人表示,8月,我国跨境资金流动和外
近期,在普陀区桃浦镇的新杨工业园区里,一批现代职业教育培育出的新生代技术人才正在工作岗位上发光发热。“00后”陈奕达是普陀区曹杨职业学校2021届汽修一班的学生,今年6月份他即将正式毕业。图说:陈奕达
深深深爱过相恒平深深深爱过 - 相恒平作词:玉镯儿作曲:相恒平编曲:石栋颖LRC BY :吉时雨QQ:132 7269 041www.555uuu.cn ★你今天嫁人了 我听朋友说用尽所有力气 才保持
บรรยากาศการซื้อขายหุ้นไทยปิดตลาดที่ระดับ 1259.42 จุด ปรับลง 7.25 จุด หรือ 0.57% มูลค่าการซื้อขาย 483
9月3日,2021年太原能源低碳发展论坛开幕。今年太原论坛主题是“能源 气候 环境”,以线上线下相结合的方式举办。本次论坛重点开展一场开幕式暨高峰论坛、一场信息发布+圆桌访谈、一批签约活动、一个线上展
在《战地6》即将发布之际,系列负责人Vince Zampella表示,虽然他“某种程度上”将《战地》视为《使命召唤》的竞争对手,但他认为《战地》拥有其他游戏无法提供的独特体验。在近日的一次采访中,Za