하루 셸 명령 Liux 텍스트 작업 시리즈-diff 명령 상세 설명

9897 단어 linuxdiff
이것 은 또 하나의 문서 비교 명령 으로 숙련 되면 많은 일 을 절약 할 수 있다.comm 명령 기억 나 세 요?diff 는 그 보다 더 복잡 하고 쓰기 좋 으 며 파일 을 비교 할 수 있 을 뿐만 아니 라 디 렉 터 리 도 비교 할 수 있 습 니 다.한 파일 에 여러 버 전이 있 을 때,혹은 더 복잡 한 파일 이 있 을 때,디 렉 터 리 를 비교 할 때,comm 보다 더 유용 한 명령 이 있 기 를 기대 할 것 입 니 다.diff 는 바로 이 때문에 생 겨 났 습 니 다.
다른 파일
실례:
파일 1:v1.txt

hello
  world v1_echo
  v1_diff
  v1_comm
 shell is easy!
파일 2:v2.txt

hello world!
v2_echo
 v1_diff
 easy shell!
1.일반 비교:
$diff v1.txt v2.txt

1,2c1,2
 < hello world
 &lt; v1_echo
 ---
 > hello world!
 &gt; v2_echo
 4c4
 < v1_comm
 ---
 > easy shell!

비교 의 차 이 를 보 여 줍 니 다.숫자 는 줄 수 이 고 c 는 compare 입 니 다.
2.일체화 출력:
$diff -u v1.txt v2.txt > version.patch

-v1_echo
 +hello world!
 +v2_echo
 v1_diff
 -v1_comm
 +easy shell!
 shell is easy!

"+"는 보충 줄 을 나타 내 고,"-"삭제 줄 을 나타 낸다.
3.덮어 쓰기 v1.txt 를 업데이트 합 니 다.patch 를 빌 렸 습 니 다.
$patch Cp1 v1.txt< version.patch
4.v1,v2 파일 비교,v2 만 출력
$diff -e v1.txt v2.txt

 4c
 easy shell!
 .
 1,2c
 hello world!
 v2_echo
 .
5.비교 목록
책 위의 설명 을 빌려 쓰다.
-N 모든 파일 을 빈 파일 로 간주
-a 모든 문서 시 위원회 문서 텍스트
-u 일체화 출력 생 성
-r 디 렉 터 리 에 있 는 모든 파일 옮 겨 다 니 기
두 디 렉 터 리 의 모든 텍스트 정 보 를 비교 합 니 다.
$diff CNaur directory1 directory2
이 두 목록 이 기본적으로 같다 고 확신 하지 않 으 면 이렇게 사용 하 는 것 을 추천 하지 않 는 다.
6.업무 피로 후,특히 많은 일 을 동시에 할 때,업로드 한 적 이 있 는 지,어떤 디 렉 터 리 에 있 는 파일 을 수정 한 적 이 있 는 지 잊어버린다.이렇게 할 수 있 습 니 다.
$diff v1.txt /${dir}
동명 의 서 류 를 직접 비교 해 보면 강도 높 은 일꾼 들 은 정말 실 감 이 난다 고 믿는다.
help
너무 길 어서 일부분 을 잘라 서 해석 해 보 세 요.

Mandatory arguments to long options are mandatory for short options too.
 --normal                                        output a normal diff (the default)
 -q, --brief                                      report only when files differ
 -s, --report-identical-files               report when two files are the same
 -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
 -e, --ed                                          output an ed script
 -n, --rcs                                         output an RCS format diff
 -y, --side-by-side                           output in two columns

FILES ‘FILE1 FILE2'、‘DIR1 DIR2'、‘DIR FILE...'
‘FILE... DIR'。

판독:
1.-q Cs
-q:두 가지 만 다 릅 니 다."두 파일 이 다르다"는 것 을 알려 줍 니 다.
-s:두 파일 을 동시에 표시 합 니 다."두 파일 이 같 습 니 다"
$diff -qs v1.txt v2.txt
(좀 지루 한 명령)
2. Cy
열의 방식 에 따라 출력 하여 직관 성 을 증가 시 켰 다.

 hello world               | hello world!
 v1_echo                    | v2_echo
 v1_diff                       v1_diff
 v1_comm                   | easy shell!
 shell is easy!               shell is easy!

3.file 뒤의 형식
1.파일 파일 2.디 렉 터 리 와 디 렉 터 리 3.파일 과 디 렉 터 리 4.디 렉 터 리 와 파일 일 수 있 습 니 다.
파일 과 디 렉 터 리 의 형식 을 설명 하고 비교 하 는 것 은 이 디 렉 터 리 에서 파일 과 같은 이름 의 파일 을 비교 하 는 것 입 니 다.
예:$diff v1.txt diff/
실제 v1.txt 와 diff/v1.txt 의 비교 입 니 다.이것 은 매우 상용 하 는 기능 이다.
대비
비교 파일 에 있어 서,comm 기능 은 비교적 간단 하지만,매우 직관 적 이 고 편리 하 다.
한편,diff 는 더욱 강력 하고 복잡 한 비교 방식 을 제공 하고 디 렉 터 리 를 비교 하여 디 렉 터 리 를 옮 겨 다 닐 수 있 습 니 다.

:diff [ ]... FILES
Compare FILES line by line.

Mandatory arguments to long options are mandatory for short options too.
      --normal                  output a normal diff (the default)
  -q, --brief                   report only when files differ
  -s, --report-identical-files  report when two files are the same
  -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
  -e, --ed                      output an ed script
  -n, --rcs                     output an RCS format diff
  -y, --side-by-side            output in two columns
  -W, --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

  -p, --show-c-function         show which C function each change is in
  -F, --show-function-line=RE   show the most recent line matching RE
      --label LABEL             use LABEL instead of file name
                                  (can be repeated)

  -t, --expand-tabs             expand tabs to spaces in output
  -T, --initial-tab             make tabs line up by prepending a tab
      --tabsize=NUM             tab stops every NUM (default 8) print columns
      --suppress-blank-empty    suppress space or tab before empty output lines
  -l, --paginate                pass output through `pr' to paginate it

  -r, --recursive                 recursively compare any subdirectories found
  -N, --new-file                  treat absent files as empty
      --unidirectional-new-file   treat absent first files as empty
      --ignore-file-name-case     ignore case when comparing file names
      --no-ignore-file-name-case  consider case when comparing file names
  -x, --exclude=PAT               exclude files that match PAT
  -X, --exclude-from=FILE         exclude files that match any pattern in FILE
  -S, --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

  -i, --ignore-case               ignore case differences in file contents
  -E, --ignore-tab-expansion      ignore changes due to tab expansion
  -Z, --ignore-trailing-space     ignore white space at line end
  -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, --ignore-matching-lines=RE  ignore changes whose lines all match RE

  -a, --text                      treat all files as text
      --strip-trailing-cr         strip trailing carriage return on input

  -D, --ifdef=NAME                output merged file with `#ifdef NAME' diffs
      --GTYPE-group-format=GFMT   format GTYPE input groups with GFMT
      --line-format=LFMT          format all input lines with LFMT
      --LTYPE-line-format=LFMT    format LTYPE input lines with LFMT
    These format options provide fine-grained control over the output
      of diff, generalizing -D/--ifdef.
    LTYPE ‘old'、‘new' ‘unchanged'。GTYPE LTYPE
    ‘changed'。
    GFMT (only) 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
      %(A=B?T:E)  if A equals B then T else E
    LFMT (only) 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
    Both GFMT and LFMT may contain:
      %%  %
      %c'C'  the single character C
      %c'\OOO'  the character with octal code OOO
      C    the character C (other characters represent themselves)

  -d, --minimal            try hard to find a smaller set of changes
      --horizon-lines=NUM  keep NUM lines of the common prefix and suffix
      --speed-large-files  assume large files and many scattered small changes

      --help               display this help and exit
  -v, --version            output version information and exit

  FILES ‘FILE1 FILE2'、‘DIR1 DIR2'、‘DIR FILE...'
      ‘FILE... DIR'。
If --from-file or --to-file is given, there are no restrictions on FILE(s).
FILE ‘-', 。
, 0;1 ;2 。

좋은 웹페이지 즐겨찾기