[질문] 압축이 지원되는 'tee' 명령은 없나요?

alfalf의 이미지

안녕하세요.
질문 그대로 'tee'에서 파일을 저장할때 압축을 해서 저장했으면 합니다.
그런 기능을 지원해 주는 명령은 없나요? 뭐 'gzip -c'를 이용하고
스크립트를 이렇게 저렇게 하면 되지만 스크립트가 지저분해지는게 싫어서요.
그럼. 부탁드리겠습니다.

alfalf의 이미지

인터넷을 찾아봐도 제가 원하는 명령이 없길래
점심먹고 머리도 식힐겸 그냥 하나 간단히 만들어 봤습니다.

#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
#include <getopt.h>
 
#define LINELEN         65536
 
const char sProgName[] = "ztee";
const char sVer[] = "0.0.1";
 
void help(void) {
        printf("%s - read from standard input and write to standard output and compressed files
 
Usage: %s [OPTION]... -f FILE
 
Copy standard input to compressed FILE, and also to standard output.
 
  -h  display help and exit
  -V  output version information and exit
", sProgName, sProgName);
}
 
 
void ver(void) {
        printf("%s %s\n", sProgName, sVer);
}
 
int main(int argc, char *argv[]) {
        int iOpt;
        char sLine[LINELEN];
        char *spOutputFileName = NULL;
        FILE *FInputFile;
        gzFile *gzOutputFile;
 
        while((iOpt = getopt(argc, argv, "f:hV")) != -1) {
                switch(iOpt) {
                case 'h':
                        help();
                        exit(0);
                case 'V':
                        ver();
                        exit(0);
                case 'f':
                        spOutputFileName = optarg;
                        break;
                default:
                        help();
                        exit(1);
                }
        }
 
        if (spOutputFileName == NULL) {
                help();
                exit(1);
        }
 
        FInputFile = stdin;
        gzOutputFile = gzopen(spOutputFileName, "wb");
 
        while(fgets(sLine, LINELEN, FInputFile)) {
                fputs(sLine, stdout);
                gzputs(gzOutputFile, sLine);
        }
 
        gzclose(gzOutputFile);
        fclose(FInputFile);
        return 0;
}

뭐 컴파일 방법은 다 아시겠지만

gcc -O3 -ansi -Wall -o ztee -lz ztee.c

그럼...

eungkyu의 이미지

#!/bin/sh

gzip -c | tee $@ | zcat

이정도로는 안되는건가요?

압축을 했다가 푸는거라 좀 찝찝하긴 한데...
그래도 가장 쉽고 편한 방법인거 같네요.