【Mac】ファイルを指定サイズで分割/結合する split/cat

コンピュータ関連
スポンサーリンク


MacやLinuxで使えるファイルを指定サイズで分割・結合するコマンド。

あれ?なんだっけ?
ってなるので備忘録。

スポンサーリンク

ファイルを指定サイズで分割「split」

ターミナル(アプリケーション → ユーティリティ)から

split -b 分割サイズ 分割元ファイル名 分割後ファイル名

例:「file.zip」というファイルを 4.5GB ごとに分割

split -b 4500m file.zip splited.

結果:
splited.aa
splited.ab
splited.ac
.
.
.
に分割される。

空白スペースなどを含むファイル名などはエラーがでることがあります。その場合はダブルクオーテーション「”」もしくはシングルクオーテーション「’」で囲みましょう。エスケープする(¥や\(バックスラッシュ)を空白の前に付ける)のも一つのやり方です。ターミナルにドラッグアンドドロップすると自動的にエスケープされます。

オプション

オプション未指定で1000行ごとに分割。

split [-a suffix_length] [-b byte_count[k|m]] [-l line_count] [-p pattern] [file [name]]

-a suffix_length
Use suffix_length letters to form the suffix of the file name.

-b byte_count[k|m]
Create smaller files byte_count bytes in length.  If ``k'' is
appended to the number, the file is split into byte_count kilo-
byte pieces.  If ``m'' is appended to the number, the file is
split into byte_count megabyte pieces.

-l line_count
Create smaller files n lines in length.

-p pattern
The file is split whenever an input line matches pattern, which
is interpreted as an extended regular expression.  The matching
line will be the first line of the next output file.  This option
is incompatible with the -b and -l options.

分割ファイルの結合「cat」

分割したファイルがあるディレクトリで

cat 分割済みファイル名.* > 結合後のファイル名

上記ファイルの復元例

cat splited.* > file.zip

結果:
file.zip

復活!

スポンサーリンク

オプション

cat [-benstuv] [file …]

	-b      Number the non-blank output lines, starting at 1.

	-e      Display non-printing characters (see the -v option), and display
	a dollar sign (`$') at the end of each line.

	-n      Number the output lines, starting at 1.

	-s      Squeeze multiple adjacent empty lines, causing the output to be
	single spaced.

	-t      Display non-printing characters (see the -v option), and display
	tab characters as `^I'.

	-u      Disable output buffering.

	-v      Display non-printing characters so they are visible.  Control
	characters print as `^X' for control-X; the delete character
	(octal 0177) prints as `^?'.  Non-ASCII characters (with the high
	bit set) are printed as `M-' (for meta) followed by the character
	for the low 7 bits.

まとめ

HDDの中身もちょっと整理しようかと作業中。
別のHDDに移しながらふと思った。

これって結局データをたらい回しにしているだけなんだよね・・・

で、その時デスクの下から埃をかぶった片面一層のDVDを大量に、でもないけどそこそこ発見。

勿体無いしせっかくだからこのDVDに焼いておくかと。

でも5GB越えのファイルなんて1枚じゃ焼けない。
そういえばあのコマンドって・・・何だっけ?

になったので改めて調べました。

コメント

タイトルとURLをコピーしました