橘子味的心
标题:Linux shell fold 命令

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

fold 命令会从指定的文件里读取内容,将超过限定列宽的列加入增列字符后,输出到标准输出设备。

若不指定任何文件名称,或是所给予的文件名为 -,则 fold 命令会从标准输入设备读取数据。

fold 命令语法格式

fold [-bs][-w<每列行数>][--help][--version][文件...]

参数

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

范例

假设存在 demo6.txt 文件,内容如下

[root@localhost ~/shell]# cat demo6.txt
Linux networks are becoming more and more common, but
security is often an overlooked
issue. Unfortunately, in today’s environment all networks
are potential hacker targets,
from top-secret military research networks to small home LANs.
Linux Network Security focuses on securing Linux in a
networked environment, where the
security of the entire network needs to be considered
rather than just isolated machines.
It uses a mix of theory and practical techniques to
teach administrators how to install and
use security applications, as well as how the
applications work and why they are necessary.

然后使用 fold 命令 以每行宽度 30 字符折行

[root@localhost ~/shell]# fold -w 30 demo6.txt
Linux networks are becoming mo
re and more common, but
security is often an overlooke
d
issue. Unfortunately, in today
’s environment all networks
are potential hacker targets,

from top-secret military resea
rch networks to small home LAN
s.
Linux Network Security focuses
 on securing Linux in a
networked environment, where t
he
security of the entire network
 needs to be considered
rather than just isolated mach
ines.
It uses a mix of theory and pr
actical techniques to
teach administrators how to in
stall and
use security applications, as
well as how the
applications work and why they
 are necessary.

返回上一级

目录

分类