2278

11 分钟

#Bash 的 fold 命令

fold [OPTION]... [FILE]...

功能

自动换行以适应宽度。

类型

可执行文件(/usr/bin/fold),属于 coreutils

参数

  • OPTION 选项:
    • -b, --bytes - 计算字节数而不是列数
    • -s, --spaces - 在空格处换行
    • -w, --width=WIDTH - 行的宽度;默认为 80
    • --help - 显示帮助
    • --version - 显示版本
  • FILE 文件列表;如果没有这个参数或指定为 -,则读取标准输入

#示例

$ echo 'Primers 编程伙伴 https://xplanc.org/primers/' | fold -w 20 Primers 编程伙伴 https://xplanc.org/ primers/

#推荐阅读

#手册

FOLD(1) User Commands FOLD(1) NAME fold - wrap each input line to fit in specified width SYNOPSIS fold [OPTION]... [FILE]... DESCRIPTION Wrap input lines in each FILE, writing to standard output. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too. -b, --bytes count bytes 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 AUTHOR Written by David MacKenzie. REPORTING BUGS GNU coreutils online help: <https://www.gnu.org/software/coreutils/> Report any translation bugs to <https://translationproject.org/team/> COPYRIGHT Copyright © 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://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. SEE ALSO fmt(1) Full documentation <https://www.gnu.org/software/coreutils/fold> or available locally via: info '(coreutils) fold invocation' GNU coreutils 9.4 April 2024 FOLD(1)

创建于 2025/11/16

更新于 2025/11/16