foldコマンドは、長い行を指定した長さに合うように折り返すことができるコマンドです。
目次
foldコマンドの利用例
長い行を折り返す
(オプションなし)
foldコマンドはデフォルトでは80文字で行を折り返します。
また、metaphysics.txtは、Aristotleの「Metaphysics」の最初の段落になります。
コマンド例
1 |
fold metaphysics.txt |
metaphysics.txt
1 |
"ALL men by nature desire to know. An indication of this is the delight we take in our senses; for even apart from their usefulness they are loved for themselves; and above all others the sense of sight. For not only with a view to action, but even when we are not going to do anything, we prefer seeing (one might say) to everything else. The reason is that this, most of all the senses, makes us know and brings to light many differences between things. |
実行結果
1 2 3 4 5 6 |
"ALL men by nature desire to know. An indication of this is the delight we take in our senses; for even apart from their usefulness they are loved for themselve s; and above all others the sense of sight. For not only with a view to action, but even when we are not going to do anything, we prefer seeing (one might say) to everything else. The reason is that this, most of all the senses, makes us kn ow and brings to light many differences between things. |
バイト単位で折り返す
(-bオプション)
-bオプションで数字を指定すると、そのバイト単位で行を折り返します。
コマンド例では、headコマンドで最初の10行だけを表示しています。
コマンド例
1 |
fold -b5 metaphysics.txt | head |
実行結果
1 2 3 4 5 6 7 8 9 10 |
"ALL men b y nat ure d esire to k now. An in dicat ion o |
単語の境界で折り返すようにする
(-sオプション)
-sオプションを用いると単語の境界で折り返すようになります。
コマンド例
1 |
fold -s metaphysics.txt |
実行結果
1 2 3 4 5 6 |
"ALL men by nature desire to know. An indication of this is the delight we take in our senses; for even apart from their usefulness they are loved for themselves; and above all others the sense of sight. For not only with a view to action, but even when we are not going to do anything, we prefer seeing (one might say) to everything else. The reason is that this, most of all the senses, makes us know and brings to light many differences between things. |
幅を指定
(-wオプション)
-wオプションで、行の最大幅を指定することができます。
また、行の最大幅はデフォルトでは80になります。
コマンド例
1 |
fold -w20 metaphysics.txt | head |
実行結果
1 2 3 4 5 6 7 8 9 10 |
"ALL men by nature d esire to know. An in dication of this is the delight we take in our senses; for e ven apart from their usefulness they are loved for themselve s; and above all oth ers the sense of sig |
参考
外部リンクGnu Coreutils
外部リンクGnu Coreutils日本語版