컴퓨터 엑셀 워드 포토샵 구글어스 WINDOWS JAVASCRIPT JAVA C++

 
Monday, May 29, 2006

유닉스/리눅스(Linux)의, 파일 비교 명령: diff


리눅스를 포함한 유닉스 계열 운영체제에 있는, 파일 비교 명령인 diff 에 대한 설명입니다.


"텍스트 파일 비교 유틸리티 WinDiff 소개 (마이크로소프트; 프리웨어)" 포스트에서 예로 들었던 이육사의 청포도라는 시를 diff 로 비교한 것입니다. (윈도우용 Win32 으로 컴파일된 diff.exe 임):

D:\Z>diff 0.txt 1.txt
5c5
<                           이육사
---
> 이육사
14d13
< 하늘 밑 푸른 바다가 가슴을 열고
18c17
< 靑袍를 입고 찾아온다고 했으니
---
> 청포를 입고 찾아온다고 했으니
23a23
> (-_-)

D:\Z>



WinDiff 와 같은 포맷입니다. 윈도우의 FC 명령의 결과보다 낫습니다. (십육진수로 보이는 이런 14d13 숫자가 무엇을 의미하는지는 잘 모르겠습니다-_- 변경 내용에 대한 구체적인 정보일 것 같습니다. 몇 행 몇 번째 문자가 변경되었다 뭐 이런 것.)


diff 의 도움말을 보기 위해서는

diff --help

이렇게 해야 합니다. (윈도우나 도스에서는 "/?" 옵션으로 도움말을 출력하지만, 유닉스/리눅스에서는 "--help" 나 "-h" 가 도움말이 나오는 옵션입니다.)




D:\Z>diff --help
Usage: diff [OPTION]... FILES
Compare files line by line.

  -i  --ignore-case  Ignore case differences in file contents.
  --ignore-file-name-case  Ignore case when comparing file names.
  --no-ignore-file-name-case  Consider case when comparing file names.
  -E  --ignore-tab-expansion  Ignore changes due to tab expansion.
  -b  --ignore-space-change  Ignore changes in the amount of white space.
  -w  --ignore-all-space  Ignore all white space.
  -B  --ignore-blank-lines  Ignore changes whose lines are all blank.
  -I RE  --ignore-matching-lines=RE  Ignore changes whose lines all match RE.
  --strip-trailing-cr  Strip trailing carriage return on input.
  --binary  Read and write data in binary mode.
  -a  --text  Treat all files as text.

  -c  -C NUM  --context[=NUM]  Output NUM (default 3) lines of copied context.
  -u  -U NUM  --unified[=NUM]  Output NUM (default 3) lines of unified context.
    --label LABEL  Use LABEL instead of file name.
    -p  --show-c-function  Show which C function each change is in.
    -F RE  --show-function-line=RE  Show the most recent line matching RE.
  -q  --brief  Output only whether files differ.
  -e  --ed  Output an ed script.
  --normal  Output a normal diff.
  -n  --rcs  Output an RCS format diff.
  -y  --side-by-side  Output in two columns.
    -W NUM  --width=NUM  Output at most NUM (default 130) print columns.
    --left-column  Output only the left column of common lines.
    --suppress-common-lines  Do not output common lines.
  -D NAME  --ifdef=NAME  Output merged file to show `#ifdef NAME' diffs.
  --GTYPE-group-format=GFMT  Similar, but format GTYPE input groups with GFMT.
  --line-format=LFMT  Similar, but format all input lines with LFMT.
  --LTYPE-line-format=LFMT  Similar, but format LTYPE input lines with LFMT.
    LTYPE is `old', `new', or `unchanged'.  GTYPE is LTYPE or `changed'.
    GFMT may contain:
      %<  lines from FILE1
      %>  lines from FILE2
      %=  lines common to FILE1 and FILE2
      %[-][WIDTH][.[PREC]]{doxX}LETTER  printf-style spec for LETTER
        LETTERs are as follows for new group, lower case for old group:
          F  first line number
          L  last line number
          N  number of lines = L-F+1
          E  F-1
          M  L+1
    LFMT may contain:
      %L  contents of line
      %l  contents of line, excluding any trailing newline
      %[-][WIDTH][.[PREC]]{doxX}n  printf-style spec for input line number
    Either GFMT or LFMT may contain:
      %%  %
      %c'C'  the single character C
      %c'\OOO'  the character with octal code OOO

  -l  --paginate  Pass the output through `pr' to paginate it.
  -t  --expand-tabs  Expand tabs to spaces in output.
  -T  --initial-tab  Make tabs line up by prepending a tab.
  --tabsize=NUM  Tab stops are every NUM (default 8) print columns.

  -r  --recursive  Recursively compare any subdirectories found.
  -N  --new-file  Treat absent files as empty.
  --unidirectional-new-file  Treat absent first files as empty.
  -s  --report-identical-files  Report when two files are the same.
  -x PAT  --exclude=PAT  Exclude files that match PAT.
  -X FILE  --exclude-from=FILE  Exclude files that match any pattern in FILE.
  -S FILE  --starting-file=FILE  Start with FILE when comparing directories.
  --from-file=FILE1  Compare FILE1 to all operands.  FILE1 can be a directory.
  --to-file=FILE2  Compare all operands to FILE2.  FILE2 can be a directory.

  --horizon-lines=NUM  Keep NUM lines of the common prefix and suffix.
  -d  --minimal  Try hard to find a smaller set of changes.
  --speed-large-files  Assume large files and many scattered small changes.

  -v  --version  Output version info.
  --help  Output this help.

FILES are `FILE1 FILE2' or `DIR1 DIR2' or `DIR FILE...' or `FILE... DIR'.
If --from-file or --to-file is given, there are no restrictions on FILES.
If a FILE is `-', read standard input.
Exit status is 0 if inputs are the same, 1 if different, 2 if trouble.

Report bugs to <bug-gnu-utils@gnu.org>.

D:\Z>


너무 옵션이 많아서 부담스럽습니다.

비교 과정에서, 공백을 무시(Ignore all white space)하는 옵션은 -w 입니다.



관련 게시물:
리눅스 명령어를 윈도우에서 사용하기; 시그윈(Cygwin) 없이 Win32로; GnuWin32



tag: linux
리눅스 Linux | 유닉스 Unix | 시그윈 Cygwin

0 Comments:

Post a Comment

<< Home RSS 2.0 feed

구글 Google 에서 제공하는 무료 블로그 서비스인 블로거 Blogger 의 인터넷 주소는 www.blogger.com 입니다. Blogger 에 블로그를 만들면, blogspot.com 이라는 주소에 블로그가 생성됩니다.
블로그를 직접 방문하지 않고도 최신 게시물을 구독하려면 RSS 2.0 feed 주소를 리더기에 등록하시면 됩니다.
Previous Posts
Monthly Archives
Top