Linux Basic: 第7章 - Linuxの基本操作間(6) 〜リダイレクションとパイプ〜

| |

リダイレクション

UNIX/Linux のリダイレクションは、プロセスの入出力を1〜2文字の記号で制御する。
他のOSでは、もう少し手間がかかり、レガシーシステムではプログラムと入出力装置を
割り当てる、JCL (Job Control Language) と呼ばれる言語を使用するものもある。
JCL 解説

パイプライン

複数のコマンドを連結して実行するための機能だが、従来のOSでは各処理で一旦、
作業ファイルに結果を吐き出し、次段へ連携する。
パイプラインは、メモリを介し連携するためファイル作成コストがかからない上に、
前段・後段が同時に稼働するため処理効率も高い。パイプで複数のコマンドを連結する場合、
sort などデータ全数を読み込んでから処理を行うコマンドは最後に回すこと。

ファイル圧縮

ファイルの圧縮は複数のコマンド(アルゴリズム)があり対象ファイルの内容によって、
圧縮効率が異なる。
拡張子対応コマンド圧縮率例(圧縮後/圧縮前)
TextBin
.gzgzip / gunzip38.8%46.7%
.xzxz / unxz38.4%60.6%
.bz2bzip2 / bunzip238.4%40.6%
テキスト /etc/httpd/httpd.conf とバイナリ /bin/ls の例
$ cp /bin/ls /etc/httpd/conf/httpd.conf .
$ ls -l httpd.conf ls
-rw-r--r-- 1 student student  11753  2月 26 12:02 httpd.conf
-rwxr-xr-x 1 student student 117608  2月 26 12:02 ls

##### gzip (.gz)
$ gzip -v httpd.conf ls
httpd.conf:      61.4% -- replaced with httpd.conf.gz
ls:      53.3% -- replaced with ls.gz
$ ls -l httpd.conf.gz ls.gz
-rw-r--r-- 1 student student  4562  2月 26 12:02 httpd.conf.gz
-rwxr-xr-x 1 student student 54976  2月 26 12:02 ls.gz
$ gunzip httpd.conf.gz ls.gz

##### xz (.xz)
$ xz -v httpd.conf ls
httpd.conf (1/2)
  100 %          4,516 B / 11.5 KiB = 0.384
ls (2/2)
  100 %        46.6 KiB / 114.9 KiB = 0.406
$ ls -l httpd.conf.xz ls.xz
-rw-r--r-- 1 student student  4516  2月 26 12:02 httpd.conf.xz
-rwxr-xr-x 1 student student 47712  2月 26 12:02 ls.xz
$ unxz httpd.conf.xz ls.xz

##### bzip2 (.bz2)
$ bzip2 -v httpd.conf ls
  httpd.conf:  2.699:1,  2.964 bits/byte, 62.95% saved, 11753 in, 4354 out.
  ls:          2.126:1,  3.764 bits/byte, 52.95% saved, 117608 in, 55329 out.
$ ls -l httpd.conf.bz2 ls.bz2
-rw-r--r-- 1 student student  4354  2月 26 12:02 httpd.conf.bz2
-rwxr-xr-x 1 student student 55329  2月 26 12:02 ls.bz2
$ bunzip2 httpd.conf.bz2 ls.bz2
バックアップとリストア - [ UP ]