1.fold介绍
linux命令fold用于将文本文件中的行进行折叠处理,使其适应特定的显示宽度。
2.fold用法
fold [参数] filename
参数 | 说明 |
-b | 指定折行的字节数,而不是列数 |
-s | 指定折叠后的每行宽度。默认宽度为80个字符 |
3.fold样例
3.1.fold版本查看
命令:
fold --version
[root@patrolagent ~]# fold --version
fold (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David MacKenzie.
[root@patrolagent ~]#
3.2.fold帮助
命令:
fold --help
[root@patrolagent ~]# fold --help
Usage: fold [OPTION]... [FILE]...
Wrap input lines in each FILE (standard input by default), writing to
standard output.
Mandatory arguments to long options are mandatory for short options too.
-b, --bytes count bytes rather than columns
-c, --characters count characters rather than columns
-s, --spaces break at spaces
-w, --width=WIDTH use WIDTH columns instead of 80
--help display this help and exit
--version output version information and exit
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'fold invocation'
[root@patrolagent ~]#
3.3.指定折叠后的每行宽度
命令:
fold -w 3 1.txt
[root@patrolagent ~]# fold -w 3 1.txt
aaa
bbb
ddd
cc
c
[root@patrolagent ~]#
3.4.制定折叠后的每行字节
命令:
fold -b3 1.txt
[root@patrolagent ~]# cat 1.txt
aaa bbb
ddd ccc
[root@patrolagent ~]# fold -b3 1.txt
aaa
bbb
dd
d c
cc
[root@patrolagent ~]#