南方的小清湖 2016-10-28 15:48:49  1644 

 收藏

分类专栏: ARM

本来这不是一个问题,因为Linux中的终端很方便,可以直接复制粘贴的。

centos 输出结果到 txt linux输出txt文件内容_centos 输出结果到 txt

之后开一个gedit文本编辑器,把复制到的内容粘贴就可以的。

不像windows的cmd控制台,需要先右键标题栏,选择编辑->全选/标记,在右键标题栏,选择复制,这么复制。

cmd搞不好,鼠标不小心一点,还可能把鼠标的一抖,辛辛苦苦标记的东西就消失了。

centos 输出结果到 txt linux输出txt文件内容_ci_02

当然,以上仅仅是是Linux存在图形界面的情况,如果在某些纯命令行界面,没有复制粘贴,需要将某条终端命令保存到一个txt文本文件的话,你仅仅需要在这条命令后面补充 > 保存的位置,或者 >> 保存的位置。其中,只用“>”是覆盖现有的结果,每一个命令结果会覆盖现有的txt文件,如果要保存很多命令结果的话,就需要建立不同文件名的txt文件。如果只用一个txt文件,要在同一个txt文件里面追加cmd命令结果,就要用“>>”替换“>” 就可以了,这条命令在Windows的cmd也是可以的,比如输入:

[plain]  < rel="noopener noreferrer" style="box-sizing: border-box;outline: none;margin-right: 10px;cursor: pointer;color: rgb(160, 160, 160);background-image: url("https://mmbiz.qpic.cn/mmbiz_png/wtOGbs9AUTgF7dicib5CdibbEWQU0F0Tiabib3cCWpNRExDxibBN5duguauxcbdicWg3bsYDZtKqH6Jpx4leK6VQblJuA/640?wx_fmt=gif");background-position: left top;background-size: initial;background-repeat: no-repeat;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: inherit;border-width: initial;border-style: none;border-color: initial;word-wrap: break-word;font-size: 9px;display: inline-block;width: 16px;height: 16px;text-indent: -2000px;" target="_blank" >view plain  < rel="noopener noreferrer" style="box-sizing: border-box;outline: none;margin-right: 10px;cursor: pointer;color: rgb(160, 160, 160);background-image: url("https://mmbiz.qpic.cn/mmbiz_png/wtOGbs9AUTgF7dicib5CdibbEWQU0F0TiabibhD66eK2SvUVm5Zw6jV8bnJx05pf3oo9KyhRlxeiaxvSwicMm3TDAjwxQ/640?wx_fmt=gif");background-position: left top;background-size: initial;background-repeat: no-repeat;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: inherit;border-width: initial;border-style: none;border-color: initial;word-wrap: break-word;font-size: 9px;display: inline-block;width: 16px;height: 16px;text-indent: -2000px;" target="_blank" >copy  

  1. ping > f:\1.txt  

就把ping这条命令的说明输出到f:\1.txt中,如下图所示:

centos 输出结果到 txt linux输出txt文件内容_txt文件_03

利用>输出命令运行结果,在Linux绝对没问题,但是如果像上面一样,利用>用来输出命令说明,比如在Linux中,输入:

[plain]  < rel="noopener noreferrer" style="box-sizing: border-box;outline: none;margin-right: 10px;cursor: pointer;color: rgb(160, 160, 160);background-image: url("https://mmbiz.qpic.cn/mmbiz_png/wtOGbs9AUTgF7dicib5CdibbEWQU0F0Tiabib3cCWpNRExDxibBN5duguauxcbdicWg3bsYDZtKqH6Jpx4leK6VQblJuA/640?wx_fmt=gif");background-position: left top;background-size: initial;background-repeat: no-repeat;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: inherit;border-width: initial;border-style: none;border-color: initial;word-wrap: break-word;font-size: 9px;display: inline-block;width: 16px;height: 16px;text-indent: -2000px;" target="_blank" >view plain  < rel="noopener noreferrer" style="box-sizing: border-box;outline: none;margin-right: 10px;cursor: pointer;color: rgb(160, 160, 160);background-image: url("https://mmbiz.qpic.cn/mmbiz_png/wtOGbs9AUTgF7dicib5CdibbEWQU0F0TiabibhD66eK2SvUVm5Zw6jV8bnJx05pf3oo9KyhRlxeiaxvSwicMm3TDAjwxQ/640?wx_fmt=gif");background-position: left top;background-size: initial;background-repeat: no-repeat;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: inherit;border-width: initial;border-style: none;border-color: initial;word-wrap: break-word;font-size: 9px;display: inline-block;width: 16px;height: 16px;text-indent: -2000px;" target="_blank" >copy  

  1. ping > 1.txt  

是无法得到ping的命令说明的,如下图,结果1.txt是被创建了,但是结果为空,利用:

[plain]  < rel="noopener noreferrer" style="box-sizing: border-box;outline: none;margin-right: 10px;cursor: pointer;color: rgb(160, 160, 160);background-image: url("https://mmbiz.qpic.cn/mmbiz_png/wtOGbs9AUTgF7dicib5CdibbEWQU0F0Tiabib3cCWpNRExDxibBN5duguauxcbdicWg3bsYDZtKqH6Jpx4leK6VQblJuA/640?wx_fmt=gif");background-position: left top;background-size: initial;background-repeat: no-repeat;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: inherit;border-width: initial;border-style: none;border-color: initial;word-wrap: break-word;font-size: 9px;display: inline-block;width: 16px;height: 16px;text-indent: -2000px;" target="_blank" >view plain  < rel="noopener noreferrer" style="box-sizing: border-box;outline: none;margin-right: 10px;cursor: pointer;color: rgb(160, 160, 160);background-image: url("https://mmbiz.qpic.cn/mmbiz_png/wtOGbs9AUTgF7dicib5CdibbEWQU0F0TiabibhD66eK2SvUVm5Zw6jV8bnJx05pf3oo9KyhRlxeiaxvSwicMm3TDAjwxQ/640?wx_fmt=gif");background-position: left top;background-size: initial;background-repeat: no-repeat;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: inherit;border-width: initial;border-style: none;border-color: initial;word-wrap: break-word;font-size: 9px;display: inline-block;width: 16px;height: 16px;text-indent: -2000px;" target="_blank" >copy  

  1. cat 1.txt  

打印1.txt同样看不到任何字符。

centos 输出结果到 txt linux输出txt文件内容_linux打开txt文件命令_04

大概Linux默认各位都是高手,无须说明了。

此时,如果要得到Linux对ping命令的说明,可以利用script命令。

如下图,先利用

[plain]  < rel="noopener noreferrer" style="box-sizing: border-box;outline: none;margin-right: 10px;cursor: pointer;color: rgb(160, 160, 160);background-image: url("https://mmbiz.qpic.cn/mmbiz_png/wtOGbs9AUTgF7dicib5CdibbEWQU0F0Tiabib3cCWpNRExDxibBN5duguauxcbdicWg3bsYDZtKqH6Jpx4leK6VQblJuA/640?wx_fmt=gif");background-position: left top;background-size: initial;background-repeat: no-repeat;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: inherit;border-width: initial;border-style: none;border-color: initial;word-wrap: break-word;font-size: 9px;display: inline-block;width: 16px;height: 16px;text-indent: -2000px;" target="_blank" >view plain  < rel="noopener noreferrer" style="box-sizing: border-box;outline: none;margin-right: 10px;cursor: pointer;color: rgb(160, 160, 160);background-image: url("https://mmbiz.qpic.cn/mmbiz_png/wtOGbs9AUTgF7dicib5CdibbEWQU0F0TiabibhD66eK2SvUVm5Zw6jV8bnJx05pf3oo9KyhRlxeiaxvSwicMm3TDAjwxQ/640?wx_fmt=gif");background-position: left top;background-size: initial;background-repeat: no-repeat;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: inherit;border-width: initial;border-style: none;border-color: initial;word-wrap: break-word;font-size: 9px;display: inline-block;width: 16px;height: 16px;text-indent: -2000px;" target="_blank" >copy  

  1. script -a 1.txt  

设定接下去的终端所有内容,都打印到1.txt这个文件,同时在终端显示结果。知道你输入:

[plain]  < rel="noopener noreferrer" style="box-sizing: border-box;outline: none;margin-right: 10px;cursor: pointer;color: rgb(160, 160, 160);background-image: url("https://mmbiz.qpic.cn/mmbiz_png/wtOGbs9AUTgF7dicib5CdibbEWQU0F0Tiabib3cCWpNRExDxibBN5duguauxcbdicWg3bsYDZtKqH6Jpx4leK6VQblJuA/640?wx_fmt=gif");background-position: left top;background-size: initial;background-repeat: no-repeat;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: inherit;border-width: initial;border-style: none;border-color: initial;word-wrap: break-word;font-size: 9px;display: inline-block;width: 16px;height: 16px;text-indent: -2000px;" target="_blank" >view plain  < rel="noopener noreferrer" style="box-sizing: border-box;outline: none;margin-right: 10px;cursor: pointer;color: rgb(160, 160, 160);background-image: url("https://mmbiz.qpic.cn/mmbiz_png/wtOGbs9AUTgF7dicib5CdibbEWQU0F0TiabibhD66eK2SvUVm5Zw6jV8bnJx05pf3oo9KyhRlxeiaxvSwicMm3TDAjwxQ/640?wx_fmt=gif");background-position: left top;background-size: initial;background-repeat: no-repeat;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: inherit;border-width: initial;border-style: none;border-color: initial;word-wrap: break-word;font-size: 9px;display: inline-block;width: 16px;height: 16px;text-indent: -2000px;" target="_blank" >copy  

  1. exit  

为止。这样打印出来的文本文件直接在图形化的gedit打开有些字符是无法正常显示的,但是如果利用 

[plain]  < rel="noopener noreferrer" style="box-sizing: border-box;outline: none;margin-right: 10px;cursor: pointer;color: rgb(160, 160, 160);background-image: url("https://mmbiz.qpic.cn/mmbiz_png/wtOGbs9AUTgF7dicib5CdibbEWQU0F0Tiabib3cCWpNRExDxibBN5duguauxcbdicWg3bsYDZtKqH6Jpx4leK6VQblJuA/640?wx_fmt=gif");background-position: left top;background-size: initial;background-repeat: no-repeat;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: inherit;border-width: initial;border-style: none;border-color: initial;word-wrap: break-word;font-size: 9px;display: inline-block;width: 16px;height: 16px;text-indent: -2000px;" target="_blank" >view plain  < rel="noopener noreferrer" style="box-sizing: border-box;outline: none;margin-right: 10px;cursor: pointer;color: rgb(160, 160, 160);background-image: url("https://mmbiz.qpic.cn/mmbiz_png/wtOGbs9AUTgF7dicib5CdibbEWQU0F0TiabibhD66eK2SvUVm5Zw6jV8bnJx05pf3oo9KyhRlxeiaxvSwicMm3TDAjwxQ/640?wx_fmt=gif");background-position: left top;background-size: initial;background-repeat: no-repeat;background-attachment: initial;background-origin: initial;background-clip: initial;background-color: inherit;border-width: initial;border-style: none;border-color: initial;word-wrap: break-word;font-size: 9px;display: inline-block;width: 16px;height: 16px;text-indent: -2000px;" target="_blank" >copy  

  1. cat 1.txt  

发现是没有乱码的。

centos 输出结果到 txt linux输出txt文件内容_linux打开txt文件命令_05

centos 输出结果到 txt linux输出txt文件内容_ci_06