Linux foldコマンド

Linux 命令大全Linuxコマンド大全

Linux foldコマンドは、ファイルの列幅を制限するために使用されます。

foldコマンドは、指定されたファイルから内容を読み取り、制限された列幅を超える列に折り返し文字を追加した後、標準出力デバイスに出力します。ファイル名を指定しない場合、または指定されたファイル名が「-」の場合は、foldコマンドは標準入力デバイスからデータを読み取ります。

構文

fold [-bs][-w<每列行数>][--help][--version][文件...]

オプション:

  • -bまたは--bytes: 列幅をByte単位で計算します。行数単位ではありません。
  • -sまたは--spaces: スペース文字を折り返し位置として使用します。
  • -w<各列の行数>または--width<各列の行数>: 各列の最大行数を設定します。
  • --help: オンラインヘルプ。
  • --version: バージョン情報を表示します。

例

testfileという名前のファイルの行を幅30に折り返すには、次のコマンドを使用します:

fold -w 30 testfile

比較のため、まずtestfileファイルを以下に出力します:

$ cat testfile #查看testfile 中的内容  
Linux networks are becoming more and more common, but 
security is often an overlooked  
issue. Unfortunately, in today’s environment all networks 
are potential hacker targets,  
from top-secret military research networks to small home LANs.  
Linux Network Security focuses on securing Linux in a 
networked environment, where the  
security of the entire network needs to be considered 
rather than just isolated machines.  
It uses a mix of theory and practical techniques to 
teach administrators how to install and  
use security applications, as well as how the 
applications work and why they are necessary. 

次にfoldコマンドを使用して折り返し表示します:

$ fold -w 30 testfile #行折叠成宽度为30,显示testfile 文件  
Linux networks are becoming mo  
re and more common, but securi  
ty is often an overlooked issu  
e. Unfortunately, in today’s  
environment all networks are  
potential hacker targets, from  
top-secret military research  
networks to small home LANs.  
Linux Network Security focuses  
on securing Linux in a networ  
ked environment, where the sec  
urity of the entire network ne  
eds to be considered rather th  
an just isolated machines. It  
uses a mix of theory and pract  
ical techniques to teach admin  
istrators how to install and u  
se security applications, as w  
ell as how the applications wo  
rk and why they are necessary 

Linux 命令大全Linuxコマンド大全

その他の拡張