⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linux 文件内容查看工具介绍 linuxsir_org.htm

📁 linuxSir 网站的精华文章
💻 HTM
📖 第 1 页 / 共 2 页
字号:
      <P>我想通过cat 把sir01.txt、sir02.txt及sir03.txt 
      三个文件连接在一起(也就是说把这三个文件的内容都接在一起)并输出到一个新的文件sir04.txt 中。</P>
      <P><B>注意:</B>其原理是把三个文件的内容连接起来,然后创建sir04.txt文件,并且把几个文件的内容同时写入sir04.txt中。特别值得一提的是,如果您输入到一个已经存在的sir04.txt 
      文件,会把sir04.txt内容清空。</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# cat sir01.txt sir02.txt 
      sir03.txt &gt; sir04.txt<BR>[root@localhost ~]# more 
      sir04.txt<BR>123456<BR>i am testing<BR>56789<BR>BeiNan 
      Tested<BR>09876<BR>linuxsir.org testing</CODE></DIV>
      <P></P>
      <P><B>cat 把一个或多个已存在的文件内容,追加到一个已存在的文件中</B></P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# cat 
      sir00.txt<BR>linuxsir.org forever<BR>[root@localhost ~]# cat sir01.txt 
      sir02.txt sir03.txt &gt;&gt; sir00.txt<BR>[root@localhost ~]# cat 
      sir00.txt<BR>linuxsir.org forever<BR>123456<BR>i am 
      testing<BR>56789<BR>BeiNan Tested<BR>09876<BR>linuxsir.org 
      testing</CODE></DIV>
      <P></P>
      <P><FONT 
      color=red><B>警告:我们要知道&gt;意思是创建,&gt;&gt;是追加。千万不要弄混了。造成失误可不是闹着玩的;</B></FONT></P>
      <P><FONT id=2 size=4><B><BR>2、more 文件内容或输出查看工具;<BR></B></FONT></P>
      <P><B><BR>more 
      是我们最常用的工具之一,最常用的就是显示输出的内容,然后根据窗口的大小进行分页显示,然后还能提示文件的百分比;<BR></B></P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# more 
      /etc/profile</CODE></DIV>
      <P></P>
      <P><FONT id=3 size=3><B><BR>2.1 more 的语法、参数和命令;<BR></B></FONT></P>
      <P>
      <DIV class=codeblock><CODE>more [参数选项] [文件]</CODE></DIV>
      <P></P><PRE><B>参数如下:</B>
+num			从第num行开始显示;
-num			定义屏幕大小,为num行;
+/pattern  	从pattern 前两行开始显示;
-c			从顶部清屏然后显示;
-d			提示Press space to continue, 'q' to quit.(按空格键继续,按q键退出),禁用响铃功能; 
-l 			忽略Ctrl+l (换页)字符;
-p 			通过清除窗口而不是滚屏来对文件进行换页。和-c参数有点相似;  
-s				把连续的多个空行显示为一行;
-u				把文件内容中的下划线去掉
</PRE>
      <P><B>退出more的动作指令是q </B></P>
      <P><FONT id=2.2 size=3><B><BR>2.2 more 的参数应用举例;<BR></B></FONT></P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# more -dc /etc/profile 
      注:显示提示,并从终端或控制台顶部显示;<BR>[root@localhost ~]# more +4 /etc/profile 
      注:从profile的第4行开始显示;<BR>[root@localhost ~]# more -4 /etc/profile 
      注:每屏显示4行;<BR>[root@localhost ~]# more +/MAIL /etc/profile 
      注:从profile中的第一个MAIL单词的前两行开始显示;</CODE></DIV>
      <P></P>
      <P><FONT id=2.3 size=3><B><BR>2.3 more 的动作指令;<BR></B></FONT></P>
      <P>我们查看一个内容较大的文件时,要用到more的动作指令,比如ctrl+f(或空格键) 是向下显示一屏,ctrl+b是返回上一屏; 
      Enter键可以向下滚动显示n行,要通过定,默认为1行;</P>
      <P>我们只说几个常用的; 自己尝试一下就知道了;</P><PRE>Enter   	   向下n行,需要定义,默认为1行;
Ctrl+f  		向下滚动一屏;
空格键        		向下滚动一屏;
Ctrl+b		返回上一屏;
=		     		输出当前行的行号;
:f 	  		输出文件名和当前行的行号;
v		  		调用vi编辑器;
! 命令          		调用Shell,并执行命令;
q 				退出more 
</PRE>
      <P>当我们查看某一文件时,想调用vi来编辑它,不要忘记了v动作指令,这是比较方便的;</P>
      <P><FONT id=2.4 size=3><B><BR>2.4 其它命令通过管道和more结合的运用例子;<BR></B></FONT></P>
      <P>比如我们列一个目录下的文件,由于内容太多,我们应该学会用more来分页显示。这得和管道 | 结合起来,比如:</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# ls -l /etc 
      |more</CODE></DIV>
      <P></P>
      <P><FONT id=4 size=4><B><BR>3、less 查看文件内容 工具;<BR></B></FONT></P>
      <P>less 
      工具也是对文件或其它输出进行分页显示的工具,应该说是linux正统查看文件内容的工具,功能极其强大;您是初学者,我建议您用less。由于less的内容太多,我们把最常用的介绍一下;</P>
      <P><FONT id=3.1 size=3><B><BR>3.1 less的语法格式;<BR></B></FONT></P>
      <P>
      <DIV class=codeblock><CODE>less [参数] 文件</CODE></DIV>
      <P></P>
      <P><B>常用参数</B><BR>
      <DIV class=codeblock><CODE>-c 从顶部(从上到下)刷新屏幕,并显示文件内容。而不是通过底部滚动完成刷新;<BR>-f 
      强制打开文件,二进制文件显示时,不提示警告;<BR>-i 搜索时忽略大小写;除非搜索串中包含大写字母;<BR>-I 
      搜索时忽略大小写,除非搜索串中包含小写字母;<BR>-m 显示读取文件的百分比;<BR>-M 显法读取文件的百分比、行号及总行数;<BR>-N 
      在每行前输出行号;<BR>-p pattern 搜索pattern;比如在/etc/profile搜索单词MAIL,就用 less -p MAIL 
      /etc/profile<BR>-s 把连续多个空白行作为一个空白行显示;<BR>-Q 在终端下不响铃;</CODE></DIV>
      <P></P>
      <P>比如:我们在显示/etc/profile的内容时,让其显示行号;</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# less -N 
      /etc/profile</CODE></DIV>
      <P></P>
      <P><FONT id=3.2 size=3><B><BR>3.2 less的动作命令;<BR></B></FONT></P>
      <P>进入less后,我们得学几个动作,这样更方便 我们查阅文件内容;最应该记住的命令就是q,这个能让less终止查看文件退出;</P>
      <P><B>动作</B><BR>
      <DIV class=codeblock><CODE>回车键 向下移动一行;<BR>y 向上移动一行;<BR>空格键 向下滚动一屏;<BR>b 
      向上滚动一屏;<BR>d 向下滚动半屏;<BR>h less的帮助;<BR>u 向上洋动半屏;<BR>w 
      可以指定显示哪行开始显示,是从指定数字的下一行显示;比如指定的是6,那就从第7行显示;<BR>g 跳到第一行;<BR>G 跳到最后一行;<BR>p 
      n% 跳到n%,比如 10%,也就是说比整个文件内容的10%处开始显示;<BR>/pattern 搜索pattern ,比如 
      /MAIL表示在文件中搜索MAIL单词;<BR>v 调用vi编辑器;<BR>q 退出less<BR>!command 
      调用SHELL,可以运行命令;比如!ls 显示当前列当前目录下的所有文件;</CODE></DIV>
      <P></P>
      <P>就less的动作来说,内容太多了,用的时候查一查man less是最好的。在这里就不举例子了;</P>
      <P><FONT id=4 size=4><B><BR>4、head 工具,显示文件内容的前几行;<BR></B></FONT><BR>head 
      是显示一个文件的内容的前多少行;</P>
      <P>用法比较简单;</P>
      <P>
      <DIV class=codeblock><CODE>head -n 行数值 文件名;</CODE></DIV>
      <P></P>
      <P>比如我们显示/etc/profile的前10行内容,应该是:</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# head -n 10 
      /etc/profile</CODE></DIV>
      <P></P>
      <P><FONT id=5 size=4><B><BR>5、tail 工具,显示文件内容的最后几行;<BR></B></FONT></P>
      <P>tail 是显示一个文件的内容的前多少行;</P>
      <P>用法比较简单;</P>
      <P>
      <DIV class=codeblock><CODE>tail -n 行数值 文件名;</CODE></DIV>
      <P></P>
      <P>比如我们显示/etc/profile的最后5行内容,应该是:</P>
      <P>
      <DIV class=codeblock><CODE>[root@localhost ~]# tail -n 5 
      /etc/profile</CODE></DIV>
      <P></P>
      <P><FONT id=6 size=4><B><BR>6、关于本文;<BR></B></FONT></P>
      <P><FONT id=7 size=4><B><BR>7、后记;<BR></B></FONT></P>
      <P><FONT id=8 size=4><B><BR>8、参考文档;<BR></B></FONT></P>
      <P><FONT id=9 size=4><B><BR>9、相关文档;<BR></B></FONT></P>
      <P><A href="http://www.linuxsir.org/main/?q=node/193"><B>《关于Linux 
      文件系统中路径的理解》</B></A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/192"><B>《Linux 
      文件和目录管理之列出、删除、复制、移动及改名》</B></A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/191"><B>《Linux 文件类型 
      及文件的扩展名》</B></A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/189"><B>《简述Linux 
      文件系统的目录结构》</B></A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/91"><B>《Linux 
      用户(user)和用户组(group)管理概述》</B></A><BR><A 
      href="http://www.linuxsir.org/main/?q=node/196"><B>《Linux 
      文件和目录的属性》</B></A></P></DIV>
      <DIV class=links>By 北南南北 at 2006/04/27 - 01:15 | <A 
      href="http://www.linuxsir.org/main/?q=taxonomy/term/1">Linux</A> | <A 
      href="http://www.linuxsir.org/main/?q=taxonomy/term/25">基础知识</A> | <A 
      href="http://www.linuxsir.org/main/?q=taxonomy/term/52">命令/SHELL/PERL</A> 
      | <A title=共享你有关本文的思想和意见。 
      href="http://www.linuxsir.org/main/?q=comment/reply/198#comment">参与评论</A> 
      | 3887 阅读</DIV></DIV><A id=comment></A>
      <FORM action=?q=comment method=post>
      <DIV><INPUT type=hidden value=198 name=edit[nid]> <A id=comment-414></A>
      <DIV class=comment>
      <H3 class=title><A class=active 
      href="http://www.linuxsir.org/main/?q=node/198#comment-414">好东西,谢过论坛的前辈了,请多多关照:)第伯a&gt;</H3>
      <DIV class=content>
      <P>萍水相逢,请多多关照:)</P></DIV>
      <DIV class=links>By zxg550 at 周六, 2006/04/29 - 09:45 | <A 
      href="http://www.linuxsir.org/main/?q=comment/reply/198/414">回复</A></DIV></DIV></DIV></FORM><!-- end content -->
      <DIV id=footer>
      <CENTER><A href="http://www.linuxsir.org/"><IMG 
      src="Linux 文件内容查看工具介绍  LinuxSir_Org.files/logo.jpg"></A> <BR><A 
      href="http://www.miibeian.gov.cn/"><FONT color=blue 
      size=3><B>闽ICP备06025536号</B></FONT></A><BR>
      <SCRIPT language=JavaScript 
      src="Linux 文件内容查看工具介绍  LinuxSir_Org.files/cyberpolice.htm"></SCRIPT>
      <BR><A href="http://www.linuxsir.org/main/?q=node/78"><FONT color=blue 
      size=3><B>© 2002-2006 LinuxSir.Org</B></FONT></A><BR></CENTER></DIV></TD>
    <TD id=sidebar-right>
      <DIV class="block block-block" id=block-block-2>
      <H2 class=title>基础知识</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/23">安装配置</A> 
        <LI><A 
        href="http://www.linuxsir.org/main/?q=taxonomy/term/1/25/">基础入门</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/22/">硬件解决</A> 

        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/21">软件管理</A> 
        <LI><A 
        href="http://www.linuxsir.org/main/?q=taxonomy/term/35/48/">重要资源</A> 
        </LI></UL></DIV></DIV>
      <DIV class="block block-block" id=block-block-4>
      <H2 class=title>软件应用</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/30">网络工具</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/32">图形图像</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/31">音乐视频</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/49">字体中文</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/33">软件其它</A> 
        </LI></UL></DIV></DIV>
      <DIV class="block block-block" id=block-block-5>
      <H2 class=title>网络服务器</H2>
      <DIV class=content>
      <UL>
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/27">文件服务器<A> 
        <LI><A 
        href="http://www.linuxsir.org/main/?q=taxonomy/term/28">Web服务器</A> 
        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/29">邮件服务器</A> 

        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/37">数据库应用</A> 

        <LI><A href="http://www.linuxsir.org/main/?q=taxonomy/term/50">服务器其它</A> 
        </LI></UL></DIV></DIV>
      <DIV class="block block-comment" id=block-comment-0>
      <H2 class=title>最新评论</H2>
      <DIV class=content>
      <DIV class=item-list>
      <UL>
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/222#comment-624">错了</A><BR>6 
        min 34 sec 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/222#comment-623">q</A><BR>26 
        min 11 sec 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/222#comment-622">有些道理</A><BR>47 
        min 40 sec 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/219#comment-621">"内置的摄像头也能用这个吗?"</A><BR>13 
        hours 52 min 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/80#comment-620">终于知道了...</A><BR>23 
        hours 7 min 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/106#comment-619">okok</A><BR>2 
        days 14 hours 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/93#comment-618">那要除去阴影呢?</A><BR>3 
        days 19 hours 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/227#comment-617">不错的机会</A><BR>4 
        days 6 hours 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/221#comment-616">配置可执行程序的路径</A><BR>4 
        days 12 hours 前
        <LI><A 
        href="http://www.linuxsir.org/main/?q=node/222#comment-615">修改hostname出现的问题</A><BR>5 
        days 2 hours 
前</LI></UL></DIV></DIV></DIV></TD></TR></TBODY></TABLE></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -