[질문] 압축이 지원되는 '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

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

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

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.