Skip to content

Latest commit

 

History

History
66 lines (52 loc) · 2.13 KB

fold命令.md

File metadata and controls

66 lines (52 loc) · 2.13 KB

fold命令

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

语法

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

参数

  • -b, --bytes: 计算字节数而不是列数。
  • -s, --spaces: 在空格处跳过。
  • -w, --width=WIDTH: 使用n列,而不是默认值80
  • --help: 显示帮助信息。
  • --version: 显示版本信息。

示例

使用fold命令进行分隔,每行最多包含默认值80个字符。

fold file.txt
# fold command in Linux wraps each line in an input file to fit a specified width
# and prints it to the standard output. By default, it wraps lines at a maximum wi
# dth of 80 columns but this is configurable. To fold input using the fold command
#  pass a file or standard input to the command.

使用fold命令进行分隔,指定每行最多包含默认值50个字符。

fold -w 50 file.txt
# fold command in Linux wraps each line in an input
# file to fit a specified width and prints it to the
#  standard output. By default, it wraps lines at a
# maximum width of 80 columns but this is configurab
# le. To fold input using the fold command pass a fi
# le or standard input to the command.

使用fold命令进行分隔,并使用-s选项用于分隔空格上的行,以便不打断单词。

fold -w 50 -s file.txt
# fold command in Linux wraps each line in an input
# file to fit a specified width and prints it to
# the standard output. By default, it wraps lines
# at a maximum width of 80 columns but this is
# configurable. To fold input using the fold
# command pass a file or standard input to the
# command.

每日一题

https://github.com/WindrunnerMax/EveryDay

参考

https://www.computerhope.com/unix/ufold.htm
https://www.runoob.com/linux/linux-comm-fold.html
https://www.geeksforgeeks.org/fold-command-in-linux-with-examples/