• 要找福利?记不住网址?搜不到?如何与我们保持联系?试试 CTRL+D 把零点博客添加进您的浏览器收藏夹,一键直达永不失联!

Linux fold命令

linux系统 涛涛 124次浏览 0个评论

Linux fold命令用于限制文件列宽。

fold指令会从指定的文件里读取内容,将超过限定列宽的列加入增列字符后,输出到标准输出设备。若不指定任何文件名称,或是所给予的文件名为”-“,则fold指令会从标准输入设备读取数据。

语法

<span class="pln">fold </span><span class="pun">[-</span><span class="pln">bs</span><span class="pun">][-</span><span class="pln">w</span><span class="pun"><每列行数>][--</span><span class="pln">help</span><span class="pun">][--</span><span class="pln">version</span><span class="pun">][文件...]</span>

参数

  • -b或–bytes 以Byte为单位计算列宽,而非采用行数编号为单位。
  • -s或–spaces 以空格字符作为换列点。
  • -w<每列行数>或–width<每列行数> 设置每列的最大行数。
  • –help 在线帮助。
  • –version 显示版本信息。

实例

将一个名为testfile 的文件的行折叠成宽度为30,可使用如下命令:

<span class="pln">fold </span><span class="pun">-</span><span class="pln">w </span><span class="lit">30</span><span class="pln"> testfile</span>

为了对比,先将testfile文件输出如下:

<span class="pln">$ cat testfile </span><span class="com">#查看testfile 中的内容  </span>
<span class="typ">Linux</span><span class="pln"> networks are becoming more </span><span class="kwd">and</span><span class="pln"> more common</span><span class="pun">,</span><span class="pln"> but 
security </span><span class="kwd">is</span><span class="pln"> often an overlooked  
issue</span><span class="pun">.</span> <span class="typ">Unfortunately</span><span class="pun">,</span> <span class="kwd">in</span><span class="pln"> today</span><span class="pun">’</span><span class="pln">s environment all networks 
are potential hacker targets</span><span class="pun">,</span>  
<span class="kwd">from</span><span class="pln"> top</span><span class="pun">-</span><span class="pln">secret military research networks to small home </span><span class="typ">LANs</span><span class="pun">.</span>  
<span class="typ">Linux</span> <span class="typ">Network</span> <span class="typ">Security</span><span class="pln"> focuses on securing </span><span class="typ">Linux</span> <span class="kwd">in</span><span class="pln"> a 
networked environment</span><span class="pun">,</span> <span class="kwd">where</span><span class="pln"> the  
security of the entire network needs to be considered 
rather than just isolated machines</span><span class="pun">.</span>  
<span class="typ">It</span><span class="pln"> uses a mix of theory </span><span class="kwd">and</span><span class="pln"> practical techniques to 
teach administrators how to install </span><span class="kwd">and</span>  
<span class="kwd">use</span><span class="pln"> security applications</span><span class="pun">,</span> <span class="kwd">as</span><span class="pln"> well </span><span class="kwd">as</span><span class="pln"> how the 
applications work </span><span class="kwd">and</span><span class="pln"> why they are necessary</span><span class="pun">.</span>

然后使用fold命令折叠显示:

<span class="pln">$ fold </span><span class="pun">-</span><span class="pln">w </span><span class="lit">30</span><span class="pln"> testfile </span><span class="com">#行折叠成宽度为30,显示testfile 文件  </span>
<span class="typ">Linux</span><span class="pln"> networks are becoming mo  
re </span><span class="kwd">and</span><span class="pln"> more common</span><span class="pun">,</span><span class="pln"> but securi  
ty </span><span class="kwd">is</span><span class="pln"> often an overlooked issu  
e</span><span class="pun">.</span> <span class="typ">Unfortunately</span><span class="pun">,</span> <span class="kwd">in</span><span class="pln"> today</span><span class="pun">’</span><span class="pln">s  
environment all networks are  
potential hacker targets</span><span class="pun">,</span> <span class="kwd">from</span><span class="pln">  
top</span><span class="pun">-</span><span class="pln">secret military research  
networks to small home </span><span class="typ">LANs</span><span class="pun">.</span>  
<span class="typ">Linux</span> <span class="typ">Network</span> <span class="typ">Security</span><span class="pln"> focuses  
on securing </span><span class="typ">Linux</span> <span class="kwd">in</span><span class="pln"> a networ  
ked environment</span><span class="pun">,</span> <span class="kwd">where</span><span class="pln"> the sec  
urity of the entire network ne  
eds to be considered rather th  
an just isolated machines</span><span class="pun">.</span> <span class="typ">It</span><span class="pln">  
uses a mix of theory </span><span class="kwd">and</span><span class="pln"> pract  
ical techniques to teach admin  
istrators how to install </span><span class="kwd">and</span><span class="pln"> u  
se security applications</span><span class="pun">,</span> <span class="kwd">as</span><span class="pln"> w  
ell </span><span class="kwd">as</span><span class="pln"> how the applications wo  
rk </span><span class="kwd">and</span><span class="pln"> why they are necessary </span>

欢迎转载本文:Linux fold命令
喜欢 (0)
[ld]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址