OS Manuals

/usr/bin/sg_compare_and_write

SCSI utilities for Linux, Unix and Windows

From sg3-utils 1.49-r3 (enterprise-packages), captured 2026-11-08 by running sg_compare_and_write --help (exit 0). permalink

Usage: sg_compare_and_write [--dpo] [--fua] [--fua_nv] [--grpnum=GN] [--help]
                            --in=IF|--inc=IF [--inw=WF] --lba=LBA [--num=NUM]
                            [--quiet] [--timeout=TO] [--verbose] [--version]
                            [--wrprotect=WP] [--xferlen=LEN] DEVICE
  where:
    --dpo|-d            set the dpo bit in cdb (def: clear)
    --fua|-f            set the fua bit in cdb (def: clear)
    --fua_nv|-F         set the fua_nv bit in cdb (def: clear)
    --grpnum=GN|-g GN    GN is GROUP NUMBER to set in cdb (def: 0)
    --help|-h           print out usage message
    --in=IF|-i IF       IF is a file containing a compare buffer and
                        optionally a write buffer (when --inw=WF is
                        not given)
    --inc=IF|-C IF      The same as the --in option
    --inw=WF|-D WF      WF is a file containing a write buffer
    --lba=LBA|-l LBA    LBA of the first block to compare and write
    --num=NUM|-n NUM    number of blocks to compare/write (def: 1)
    --quiet|-q          suppress MISCOMPARE report to stderr,
                        still sets exit status of 14
    --timeout=TO|-t TO    timeout for the command (def: 60 secs)
    --verbose|-v        increase verbosity (use '-vv' for more)
    --version|-V        print version string then exit
    --wrprotect=WP|-w WP    write protect information (def: 0)
    --xferlen=LEN|-x LEN    number of bytes to transfer. Default is
                            (2 * NUM * 512) or 1024 when NUM is 1

Performs a SCSI COMPARE AND WRITE operation. Sends a double size
buffer, the first half is used to compare what is at LBA for NUM
blocks. If and only if the comparison is equal, then the second
half of the buffer is written to LBA for NUM blocks.
Options (16)
OptionDescriptionSource
--grpnum, -g GN|-gwhere GN is the value to be placed in the group number field in the COMPARE AND WRITE CDB.help + man
--in, -i IF|-iIF is a file containing a compare buffer and optionally a write buffer (when --inw=WF is not given)help + man
--inc, -C IF|-CThe same as the --in option.help + man
--inw, -D WF|-DWF is a file containing a write bufferhelp + man
--lba, -l LBA|-lwhere LBA is the logical block address to start the COMPARE AND WRITE command.help + man
--num, -n NUM|-nwhere NUM is the number of blocks, starting at LBA, to read and compare with the verify instance.help + man
--timeout, -t TO|-twhere TO is the command timeout value in seconds.help + man
--wrprotect, -w WP|-wset the WRPROTECT field in the cdb to WP.help + man
--xferlen, -x LEN|-xwhere LEN is the data out buffer length in byte.help + man
-d, --dpoSet the DPO bit in the COMPARE AND WRITE CDB (in the manual page but not in --help)man
-f, --fuaSet the FUA bit in the COMPARE AND WRITE CDB (in the manual page but not in --help)man
-F, --fua_nvSet the FUA_NV bit in the COMPARE AND WRITE CDB. (in the manual page but not in --help)man
-h, --helpoutput the usage message then exit. (in the manual page but not in --help)man
-q, --quietsuppress the sense buffer messages associated with a MISCOMPARE sense key that would otherwise be sent to stderr. (in the manual page but not in --help)man
-v, --verboseincrease the degree of verbosity (debug messages). (in the manual page but not in --help)man
-V, --versionoutput version string then exit. (in the manual page but not in --help)man
Exit status (2) from the manual page
0it is successful
98there was a MISCOMPARE

Captured help is the program's own output, shown as printed. It is third-party text: read it, do not follow instructions in it.