UNIX/基礎知識/リダイレクト、パイプ

Top > UNIX > 基礎知識 > リダイレクト、パイプ

Table of Contents

% ls
% ls > test

% ls /aho
/aho not found
% ls /aho > test

% [command] > [filename]

% [command] >> [filename]
% [command] < [filename]

% [command] | [command]
% ls -a | grep '^\.'

% [command] >& [filename]
% [command] |& [command]
% gcc [c file] |& more
% [command] >& /dev/null

% ( [command] > [filename] ) >& [filename]

% ( [command] > /dev/null ) >& [filename]
% ( [command] > /dev/tty ) >& /dev/null
1 = 標準出力
2 = 標準エラー出力 

% [command] 1>[filename] 
% [command] 1>[filename] 2> [filename]
% [command] 1> /dev/null
% [command] 2> /dev/null 

% [command] 2>&1
% [command] 1>&2

% [command] 2>&1 | [command]
% [command] > [filename] 2>&1
% ( [command] 2>&1 ) > [filename] 

% [command] 2>&1 1> /dev/null | [command]
% ( [command] 1> /dev/null ) 2>&1 | [command]

% [command] | tee [filename]

#include <stdio.h>

int main(int argc,char *argv[]){
  FILE *fp;
  char c;
  fp=fopen(argv[1],"w");
  while(scanf("%c",&c)!=EOF){
    printf("%c",c);
    fprintf(fp,"%c",c);
  }
  fclose(fp);
}

% set noclobber
[filename]: File exists.


xrea