Original author(s) | Dennis Ritchie (AT&T Bell Laboratories) |
---|---|
Developer(s) | Various open-source and commercial developers |
Initial release | November 3, 1971 |
Written in | Plan 9: C |
Operating system | Unix, Unix-like, Plan 9, Inferno, OS-9, IBM i |
Type | Command |
License | coreutils: GPLv3+ Plan 9: MIT License |
In computing, cmp
is a command-line utility on Unix and Unix-like operating systems that compares two files of any type and writes the results to the standard output. By default, cmp
is silent if the files are the same; if they differ, the byte and line number at which the first difference occurred is reported. The command is also available in the OS-9 shell. [1]
cmp
is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification. [2] It first appeared in Version 1 Unix. [3] The version of cmp
bundled in GNU coreutils was written by Torbjorn Granlund and David MacKenzie. [4] The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities. [5] The cmp command has also been ported to the IBM i operating system. [6]
cmp
may be qualified by the use of command-line switches. The switches supported by notable implementations of cmp
are:
Name | Description | Unix | Plan 9 | Inferno | FreeBSD | Linux | IBM i |
---|---|---|---|---|---|---|---|
-b, | Print the differing bytes. Display control bytes as a '^ ' followed by a letter of the alphabet and precede bytes that have the high bit set with 'M- ' (which stands for "meta"). | No | No | No | No | Yes | No |
-h | Do not follow symbolic links. | No | No | No | Yes | No | No |
-i SKIP, | Skip the first SKIP bytes of input. | No | No | No | No | Yes | No |
-i SKIP1:SKIP2, | Skip the first SKIP1 bytes of FILE1 and the first SKIP2 bytes of FILE2. | No | No | No | No | Yes | No |
-l, | Output the (decimal) byte numbers and (octal) values of all differing bytes, instead of the default standard output. Also, output the EOF message if one file is shorter than the other. | Yes | Yes | Yes | Yes | Yes | Yes |
-L | Print the line number of the first differing byte. | Yes | Yes | Yes | No | No | No |
-n LIMIT, | Compare at most LIMIT bytes. | No | No | No | No | Yes | No |
-s, | Output nothing; yield exit status only. | Yes | Yes | Yes | Yes | Yes | Yes |
-t | Text mode where the files are opened in text mode and translated to the CCSID of the job before comparing byte for byte. | No | No | No | No | No | Yes |
-v, | Output version info. | No | No | No | No | Yes | No |
-x | Like -l but prints in hexadecimal and using zero as index for the first byte in the files. | No | No | No | Yes | No | No |
-z | For regular files compare file sizes first, and fail the comparison if they are not equal. | No | No | No | Yes | No | No |
--help | Outputs a help file. | No | No | No | No | Yes | No |
Operands that are byte counts are normally decimal, but may be preceded by '0
' for octal and '0x
' for hexadecimal.
A byte count can be followed by a suffix to specify a multiple of that count; in this case an omitted integer is understood to be 1. A bare size letter, or one followed by 'iB
', specifies a multiple using powers of 1024. A size letter followed by 'B
' specifies powers of 1000 instead. For example, '-n 4M
' and '-n 4MiB
' are equivalent to '-n 4194304
', whereas '-n 4MB
' is equivalent to '-n 4000000
'. This notation is upward compatible with the SI prefixes [7] for decimal multiples and with the IEC 60027-2 prefixes for binary multiples. [8]
Comparing
:020000040007F3 :10E00000840D80E501000000010000000100000017 :10E01000000000000000000070DE010062A726542E with :020000040007F3 :10E44400840D80E501000000010000000100000017 :10E01000000000000000000070DE010062A726542E > cmp 0 00 0 00 differ: char 21, line 2 > cmp -l 0 00 # note: byte location is in decimal, contents is in octal 21 64 60 22 64 60 23 64 60
In computing, tar is a computer software utility for collecting many files into one archive file, often referred to as a tarball, for distribution or backup purposes. The name is derived from "tape archive", as it was originally developed to write data to sequential I/O devices with no file system of their own. The archive data sets created by tar contain various file system parameters, such as name, timestamps, ownership, file-access permissions, and directory organization. POSIX abandoned tar in favor of pax, yet tar sees continued widespread use.
The ln
command is a standard Unix command utility used to create a hard link or a symbolic link (symlink) to an existing file or directory. The use of a hard link allows multiple filenames to be associated with the same file since a hard link points to the inode of a given file, the data of which is stored on disk. On the other hand, symbolic links are special files that refer to other files by name.
In computing, touch
is a command used to update the access date and/or modification date of a computer file or directory. It is included in Unix and Unix-like operating systems, TSC's FLEX, Digital Research/Novell DR DOS, the AROS shell, the Microware OS-9 shell, and ReactOS. The command is also available for FreeDOS and Microsoft Windows.
The archiver, also known simply as ar, is a Unix utility that maintains groups of files as a single archive file. Today, ar
is generally used only to create and update static library files that the link editor or linker uses and for generating .deb packages for the Debian family; it can be used to create archives for any purpose, but has been largely replaced by tar
for purposes other than static libraries. An implementation of ar
is included as one of the GNU Binutils.
xargs is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command.
dd is a command-line utility for Unix, Plan 9, Inferno, and Unix-like operating systems and beyond, the primary purpose of which is to convert and copy files. On Unix, device drivers for hardware and special device files appear in the file system just like normal files; dd can also read and/or write from/to these files, provided that function is implemented in their respective driver. As a result, dd can be used for tasks such as backing up the boot sector of a hard drive, and obtaining a fixed amount of random data. The dd program can also perform conversions on the data as it is copied, including byte order swapping and conversion to and from the ASCII and EBCDIC text encodings.
tr is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. It is an abbreviation of translate or transliterate, indicating its operation of replacing or removing specific characters in its input data set.
wc
is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. The program reads either standard input or a list of computer files and generates one or more of the following statistics: newline count, word count, and byte count. If a list of files is provided, both individual file and total statistics follow.
In computing, cut
is a command line utility on Unix and Unix-like operating systems which is used to extract sections from each line of input — usually from a file. It is currently part of the GNU coreutils package and the BSD Base System.
df is a standard Unix command used to display the amount of available disk space for file systems on which the invoking user has appropriate read access. df is typically implemented using the statfs or statvfs system calls.
du
is a standard Unix program used to estimate file space usage—space used under a particular directory or files on a file system. A Windows commandline version of this program is part of Sysinternals suite by Mark Russinovich.
mv
is a Unix command that moves one or more files or directories from one place to another. If both filenames are on the same filesystem, this results in a simple file rename; otherwise the file content is copied to the new location and the old file is removed. Using mv
requires the user to have write permission for the directories the file will move between. This is because mv
changes the content of both directories involved in the move. When using the mv
command on files located on the same filesystem, the file's timestamp is not updated.
The file
command is a standard program of Unix and Unix-like operating systems for recognizing the type of data contained in a computer file.
rm
is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files, directories and symbolic links from file systems and also special files such as device nodes, pipes and sockets, similar to the del
command in MS-DOS, OS/2, and Microsoft Windows. The command is also available in the EFI shell.
In computing, tee
is a command in command-line interpreters (shells) using standard streams which reads standard input and writes it to both standard output and one or more files, effectively duplicating its input. It is primarily used in conjunction with pipes and filters. The command is named after the T-splitter used in plumbing.
test is a command-line utility found in Unix, Plan 9, and Unix-like operating systems that evaluates conditional expressions. test was turned into a shell builtin command in 1981 with UNIX System III and at the same time made available under the alternate name [.
In computing, sleep is a command in Unix, Unix-like and other operating systems that suspends program execution for a specified time.
od
is a command on various operating systems for displaying ("dumping") data in various human-readable output formats. The name is an acronym for "octal dump" since it defaults to printing in the octal data format.
The csplit
command in Unix and Unix-like operating systems is a utility that is used to split a file into two or more smaller files determined by context lines.
cat
is a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to (con)catenate files. It has been ported to a number of operating systems.