logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

cmp.1 (2049B)


  1. .\" utils-std: Collection of commonly available Unix tools
  2. .\" Copyright 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. .\" SPDX-License-Identifier: MPL-2.0
  4. .Dd 2024-05-02
  5. .Dt CMP 1
  6. .Os
  7. .Sh NAME
  8. .Nm cmp
  9. .Nd compare two files
  10. .Sh SYNOPSIS
  11. .Nm
  12. .Op Fl ls
  13. .Op Fl n Ar max_bytes
  14. .Ar file1
  15. .Ar file2
  16. .Sh DESCRIPTION
  17. The
  18. .Nm
  19. utility checks files
  20. .Ar file1
  21. and
  22. .Ar file2
  23. for a different byte and prints it out.
  24. .Sh OPTIONS
  25. The following options are supported:
  26. .Bl -tag -width __
  27. .It Fl l
  28. Write the byte number and if found, the two bytes found different.
  29. .It Fl n Ar max_bytes
  30. Only compare the first
  31. .Ar max_bytes .
  32. .It Fl s
  33. Write nothing when files differ, errors are still printed out to stderr.
  34. .El
  35. .Sh STDOUT
  36. When a difference is found, the default message format is:
  37. .Bd -ragged -offset indent -compact
  38. .Dq %s %s differ: char %d, line %d\en ,
  39. .Ar file1 ,
  40. .Ar file2 ,
  41. .Aq Ar byte position within line
  42. .Aq Ar line position
  43. .Ed
  44. .Pp
  45. When
  46. .Fl l
  47. is passed, the format is:
  48. .Bd -ragged -offset indent -compact
  49. .Dq %d %o %o\en ,
  50. .Aq Ar byte position ,
  51. .Aq Ar file1 byte ,
  52. .Aq Ar file2 byte
  53. .Ed
  54. .Pp
  55. When
  56. .Fl s
  57. is passed, nothing should be printed to standard output.
  58. .Sh STDERR
  59. If
  60. .Fl s
  61. is not passed, and a file is shorter than the other,
  62. an error with the following format is printed:
  63. .Bd -ragged -offset indent
  64. .Dq cmp: EOF on %s line %ld\en ,
  65. .Aq Ar name of shorter file ,
  66. .Aq Ar line number
  67. .Ed
  68. .Pp
  69. Note that unlike the other formats, only the following format is standard:
  70. .Bd -ragged -offset indent -compact
  71. .Dq cmp: EOF on %s%s\en ,
  72. .Aq Ar name of shorter file ,
  73. .Aq Ar additional info
  74. .Ed
  75. Where
  76. .Aq Ar additional info
  77. can be empty or have any single-line information starting with a space.
  78. .Sh EXIT STATUS
  79. .Bl -tag -width __
  80. .It 0
  81. The files are identical.
  82. .It 1
  83. The files are different.
  84. .It >1
  85. An error occurred.
  86. .El
  87. .Sh STANDARDS
  88. .Nm
  89. should be compliant with the
  90. IEEE Std 1003.1-2024 (“POSIX.1”)
  91. specification.
  92. The
  93. .Fl n Ar max_bytes
  94. option is an extension.
  95. .Sh AUTHORS
  96. .An Haelwenn (lanodan) Monnier Aq Mt contact+utils@hacktivis.me