📄 linux 文件内容查看工具介绍 linuxsir_org.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0040)http://www.linuxsir.org/main/?q=node/198 -->
<HTML lang=zh-hans xml:lang="zh-hans"
xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>Linux 文件内容查看工具介绍 | LinuxSir.Org</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<STYLE type=text/css media=all>@import url( misc/drupal.css );
</STYLE>
<STYLE type=text/css media=all>@import url( modules/taxonomy_context/taxonomy_context.css );
</STYLE>
<LINK media=screen
href="Linux 文件内容查看工具介绍 LinuxSir_Org.files/menuExpandable3.css" type=text/css
rel=stylesheet>
<SCRIPT src="Linux 文件内容查看工具介绍 LinuxSir_Org.files/menuExpandable3.js"
type=text/javascript></SCRIPT>
<LINK href="Linux 文件内容查看工具介绍 LinuxSir_Org.files/common.css" type=text/css
rel=stylesheet>
<STYLE type=text/css media=all>@import url( themes/chameleon/marvin/style.css );
</STYLE>
<META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD>
<BODY>
<DIV id=header><A title=Home href="http://www.linuxsir.org/main/"><IMG alt=Home
src="Linux 文件内容查看工具介绍 LinuxSir_Org.files/logo.jpg"></A></DIV>
<DIV class=navlinks>
<DIV class=primary><A href="http://www.linuxsir.org/main/?q"><FONT
color=white>首页</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=taxonomy/term/34"><FONT
color=white>事件</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=taxonomy/term/1/25/"><FONT
color=white>文档</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=taxonomy/term/35/48/"><FONT
color=white>资源</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=search"><FONT color=white>搜索</FONT></A> |
<A href="http://www.linuxsir.org/bbs"><FONT color=white>论坛</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=taxonomy/term/38"><FONT
color=white>贡献者</FONT></A> | <A
href="http://www.linuxsir.org/main/?q=node/3"><FONT color=white>关于</FONT></A> |
<A href="http://www.linuxsir.org/main/?q=user"><FONT
color=white>注册/登录</FONT></A></DIV></DIV>
<TABLE id=content>
<TBODY>
<TR>
<TD id=sidebar-left>
<DIV class="block block-block" id=block-block-1>
<H2 class=title>子站索引</H2>
<DIV class=content>
<UL>
<LI><A href="http://fedora.linuxsir.org/" target?_blank?>Fedora中文</A>
<LI><A href="http://debian.linuxsir.org/" target?_blank?>Debian中文</A>
<LI><A href="http://lfs.linuxsir.org/" target?_blank?>LFS 中文</A>
<LI><A href="http://slack.linuxsir.org/">Slackware</A>
<LI><A href="http://gentoo.linuxsir.org/">Gentoo中文</A>
<LI><A href="http://arch.linuxsir.org/">Arch 中文</A> </LI></UL></DIV></DIV>
<DIV class="block block-block" id=block-block-3>
<H2 class=title>重要资讯</H2>
<DIV class=content>
<UL>
<LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/36">本站公告</A>
<LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/34">新闻事件</A>
<LI><A href="http://www.linuxsir.org/bbs" target=_blank>本站论坛</A>
<LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/38">贡 献 者</A>
</LI></UL></DIV></DIV>
<DIV class="block block-block" id=block-block-7>
<H2 class=title>项目索引</H2>
<DIV class=content>
<UL>
<LI><A href="http://www.fcitx.org/" target=_blank>小企鹅输入法</A>
<LI><A href="http://lumaqq.linuxsir.org/" target=_blank>LumaQQ</A>
<LI><A href="http://openq.linuxsir.org/" target=_blank>OpenQ</A>
<LI><A href="http://www.relaxbsd.org/" target=_blank>RelaxBSD</A>
</LI></UL></DIV></DIV>
<DIV class="block block-user" id=block-user-1>
<H2 class=title>站点导航</H2>
<DIV class=content>
<DIV class=menu>
<UL>
<LI class=leaf><A title=注册/登录
href="http://www.linuxsir.org/main/?q=user">注册/登录</A>
<LI class=collapsed><A
href="http://www.linuxsir.org/main/?q=aggregator">新闻聚合</A>
</LI></UL></DIV></DIV></DIV>
<DIV class="block block-aggregator" id=block-aggregator-feed-2>
<H2 class=title>LinuxSir.Org 论坛</H2>
<DIV class=content>
<DIV class=item-list>
<UL>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266922&goto=newpost">如何在FvwmButtons中使用系统托盘?</A>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266921&goto=newpost">FC5
root 的垃圾箱被彻底删掉了,怎么恢复?</A>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266920&goto=newpost">我想做一个mini
linux 该怎么下手呢~</A>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266919&goto=newpost">FC5体验之影音篇</A>
<LI><A
href="http://www.linuxsir.org/bbs/showthread.php?t=266918&goto=newpost">请教高手:FEDORA
4 安装问题</A> </LI></UL></DIV>
<DIV class=more-link><A title=查看此feed的最新消息
href="http://www.linuxsir.org/main/?q=aggregator/sources/2">更多</A></DIV></DIV></DIV>
<DIV class="block block-user" id=block-user-2>
<H2 class=title>最新注册</H2>
<DIV class=content>
<DIV class=item-list>
<UL>
<LI>horiwa
<LI>jiechu
<LI>emiss
<LI>ismart
<LI>mynamewsy</LI></UL></DIV></DIV></DIV>
<DIV class="block block-user" id=block-user-3>
<H2 class=title>当前在线</H2>
<DIV class=content>0 users 和 59 游客 在线</DIV></DIV></TD>
<TD id=main>
<DIV class=breadcrumb><A href="http://www.linuxsir.org/main/?q=">首页</A> »
<A href="http://www.linuxsir.org/main/?q=taxonomy/term/1">Linux</A></DIV>
<H2>Linux 文件内容查看工具介绍</H2><!-- begin content -->
<DIV class=node>
<DIV class=content>
<P><B>作者:</B>北南南北<BR><B>来自:</B>LinuxSir.Org<BR><B>摘要:</B>
本文讲述几种常用文件内容的查看工具,比如cat、more、less、head、tail等,把这些工具最常用的参数、动作介绍给新手,能让新手在短短的几分钟内上手运用。此文献给面对黑色的控制台不知所措的弟兄。</P>
<P><FONT size=4><B>目录</B></FONT></P>
<UL><A href="http://www.linuxsir.org/main/?q=node/198#1">1、cat
显示文件连接文件内容的工具;</A>
<P></P>
<UL><A href="http://www.linuxsir.org/main/?q=node/198#1.0">1.0 cat
语法结构;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/198#1.1">1.1 cat
查看文件内容实例;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/198#1.2">1.2 cat
的创建、连接文件功能实例;</A> </UL>
<P><A href="http://www.linuxsir.org/main/?q=node/198#2">2、more
文件内容或输出查看工具;</A></P>
<UL><A href="http://www.linuxsir.org/main/?q=node/198#2.1">2.1 more
的语法、参数和动作命令;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/198#2.2">2.2 more
的参数应用举例;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/198#2.3">2.3 more
的动作指令;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/198#2.4">2.4
其它命令通过管道和more结合的运用例子;</A> </UL>
<P><A href="http://www.linuxsir.org/main/?q=node/198#3">3、less 查看文件内容
工具;</A></P>
<UL><A href="http://www.linuxsir.org/main/?q=node/198#3.1">3.1
less的语法格式;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/198#3.2">3.2 less的动作命令;</A>
</UL>
<P><A href="http://www.linuxsir.org/main/?q=node/198#4">4、head
工具,显示文件内容的前几行;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/198#5">5、tail
工具,显示文件内容的最后几行;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/198#6">6、关于本文;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/198#7">7、后记;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/198#8">8、参考文档;</A><BR><A
href="http://www.linuxsir.org/main/?q=node/198#9">9、相关文档;</A> </P></UL>
<P><FONT
color=blue><B><BR>+++++++++++++++++++++++++++++++++++++<BR>正文<BR>+++++++++++++++++++++++++++++++++++++<BR></B></FONT></P>
<P><FONT id=1 size=4><B><BR>1、cat 显示文件连接文件内容的工具;<BR></B></FONT></P>
<P>cat 是一个文本文件查看和连接工具。查看一个文件的内容,用cat比较简单,就是cat 后面直接接文件名。</P>
<P>比如:<BR>
<DIV class=codeblock><CODE>[root@localhost ~]# cat /etc/fstab</CODE></DIV>
<P></P>
<P>为了便于新手弟兄灵活掌握这个工具,我们多说一点常用的参数;</P>
<P><FONT id=1.0 size=3><B><BR>1.0 cat 语法结构;<BR></B></FONT></P>
<P>
<DIV class=codeblock><CODE>cat [选项] [文件]...</CODE></DIV>
<P></P><PRE>
<B>选项</B>
-A, --show-all 等价于 -vET
-b, --number-nonblank 对非空输出行编号
-e 等价于 -vE
-E, --show-ends 在每行结束处显示 $
-n, --number 对输出的所有行编号
-s, --squeeze-blank 不输出多行空行
-t 与 -vT 等价
-T, --show-tabs 将跳格字符显示为 ^I
-u (被忽略)
-v, --show-nonprinting 使用 ^ 和 M- 引用,除了 LFD 和 TAB 之外
--help 显示此帮助信息并离开
</PRE>
<P><FONT id=1.1 size=3><B><BR>1.1 cat 查看文件内容实例;<BR></B></FONT></P>
<P>
<DIV class=codeblock><CODE>[root@localhost ~]# cat /etc/profile
注:查看/etc/目录下的profile文件内容;<BR>[root@localhost ~]# cat -b /etc/fstab
注:查看/etc/目录下的profile内容,并且对非空白行进行编号,行号从1开始;<BR>[root@localhost ~]# cat -n
/etc/profile 注:对/etc目录中的profile的所有的行(包括空白行)进行编号输出显示;<BR>[root@localhost
~]# cat -E /etc/profile 注:查看/etc/下的profile内容,并且在每行的结尾处附加$符号;</CODE></DIV>
<P></P>
<P>cat 加参数-n 和nl工具差不多,文件内容输出的同时,都会在每行前面加上行号;</P>
<P>
<DIV class=codeblock><CODE>[root@localhost ~]# cat -n
/etc/profile<BR>[root@localhost ~]# nl /etc/profile</CODE></DIV>
<P></P>
<P>cat 可以同时显示多个文件的内容,比如我们可以在一个cat命令上同时显示两个文件的内容;</P>
<P>
<DIV class=codeblock><CODE>[root@localhost ~]# cat /etc/fstab
/etc/profile</CODE></DIV>
<P></P>
<P>cat 对于内容极大的文件来说,可以通过管道|传送到more 工具,然后一页一页的查看;</P>
<P>
<DIV class=codeblock><CODE>[root@localhost ~]# cat /etc/fstab /etc/profile
| more</CODE></DIV>
<P></P>
<P><FONT id=1.2 size=3><B><BR>1.2 cat 的创建、连接文件功能实例;<BR></B></FONT></P>
<P><B><BR>cat 有创建文件的功能,创建文件后,要以EOF或STOP结束;<BR></B></P>
<P>
<DIV class=codeblock><CODE>[root@localhost ~]# cat > linuxsir.org.txt
<< EOF 注:创建linuxsir.org.txt文件;<BR>> 我来测试 cat 创建文件,并且为文件输入内容;
注:这是为linuxsir.org.txt文件输入内容;<BR>> 北南南北 测试;
注:这是为linuxsir.org.txt文件输入内容;<BR>> EOF 注:退出编辑状态;<BR>[root@localhost ~]#
cat linuxsir.org.txt 注:我们查看一下linuxsir.org.txt文件的内容;<BR>我来测试 cat
创建文件,并且为文件输入内容;<BR>北南南北 测试;</CODE></DIV>
<P></P>
<P><B>cat 还有向已存在的文件追加内容的功能;</B></P>
<P>
<DIV class=codeblock><CODE>[root@localhost ~]# cat linuxsir.txt
注:查看已存在的文件linuxsir.txt 内容;<BR>I am BeiNanNanBei From LinuxSir.Org .
注:内容行<BR>我正在为cat命令写文档<BR>[root@localhost ~]# cat >> linuxsir.txt
<< EOF 注:我们向linuxsir.txt文件追加内容;<BR>> 我来测试cat向文档追加内容的功能;
注:这是追回的内容<BR>> OK?<BR>> OK~<BR>> 北南 呈上<BR>> EOF
注:以EOF退出;<BR>[root@localhost ~]# cat linuxsir.txt 注:查看文件内容,看是否追回成功。<BR>I
am BeiNanNanBei From LinuxSir.Org
.<BR>我正在为cat命令写文档<BR>我来测试cat向文档追加内容的功能;<BR>OK?<BR>OK~<BR>北南
呈上</CODE></DIV><BR><BR><BR><B>cat 连接多个文件的内容并且输出到一个新文件中;</B>
<P></P>
<P>假设我们有sir01.txt、sir02.tx和sir03.txt ,并且内容如下;</P>
<P>
<DIV class=codeblock><CODE>[root@localhost ~]# cat
sir01.txt<BR>123456<BR>i am testing<BR>[root@localhost ~]# cat
sir02.txt<BR>56789<BR>BeiNan Tested<BR>[root@localhost ~]# cat
sir03.txt<BR>09876<BR>linuxsir.org testing</CODE></DIV>
<P></P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -