Comparison function that compares two text files in Unix

前端 未结 5 2063
走了就别回头了
走了就别回头了 2021-02-07 12:54

I was wondering if anyone could tell me if there is a function available in unix, bash that compares all of the lines of the files. If they are different it should output true/f

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-07 13:13

    There is a simple cmp file file command that does just that. It returns 0 if they are equal and 1 if they are different, so it's trivial to use in ifs:

    if cmp file1 file1; then
        ...
    fi
    

    Hope this helps =)

提交回复
热议问题