← 返回命令列表

Linux command

fold 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Fold

fold -w [60] [path/to/file]

Example

fold -s -w [60] [path/to/file]

Example

fold -b -w [60] [path/to/file]

Example

fold -c -w [60] [path/to/file]

Example

echo "long line of text" | fold -w [40]

说明

Fold wraps each input line to fit within a specified width, writing the result to standard output. By default, it counts columns and folds at exactly 80 characters, which may split words in the middle. The -s option improves readability by breaking lines at the rightmost space within the width limit, preserving whole words when possible. Without a file argument (or with -), fold reads from standard input. Width counting differs between modes: columns (default) accounts for tab expansion and multibyte characters, -b counts raw bytes, and -c counts characters regardless of display width.

参数

-w, --width _width_
Use specified width instead of default 80 columns
-s, --spaces
Break at spaces (word boundaries) within the width limit
-b, --bytes
Count bytes rather than columns
-c, --characters
Count characters rather than columns
--help
Display help and exit
--version
Output version information and exit

FAQ

What is the fold command used for?

Fold wraps each input line to fit within a specified width, writing the result to standard output. By default, it counts columns and folds at exactly 80 characters, which may split words in the middle. The -s option improves readability by breaking lines at the rightmost space within the width limit, preserving whole words when possible. Without a file argument (or with -), fold reads from standard input. Width counting differs between modes: columns (default) accounts for tab expansion and multibyte characters, -b counts raw bytes, and -c counts characters regardless of display width.

How do I run a basic fold example?

Run `fold -w [60] [path/to/file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -w, --width _width_ do in fold?

Use specified width instead of default 80 columns