{
    "mode": "man",
    "parameter": "sg_read_attr",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/sg_read_attr/8/json",
    "generated": "2026-06-15T16:42:24Z",
    "synopsis": "sgreadattr  [--cache]  [--enumerate] [--ea=EA] [--filter=FL] [--first=FAI] [--help] [--hex]\n[--in=FN] [--lvn=LVN]  [--maxlen=LEN]  [--pn=PN]  [--quiet]  [--raw]  [--readonly]  [--sa=SA]\n[--verbose] [--version] DEVICE",
    "sections": {
        "NAME": {
            "content": "sgreadattr - send SCSI READ ATTRIBUTE command\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "sgreadattr  [--cache]  [--enumerate] [--ea=EA] [--filter=FL] [--first=FAI] [--help] [--hex]\n[--in=FN] [--lvn=LVN]  [--maxlen=LEN]  [--pn=PN]  [--quiet]  [--raw]  [--readonly]  [--sa=SA]\n[--verbose] [--version] DEVICE\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Sends a SCSI READ ATTRIBUTE command to DEVICE and outputs the data returned. This command was\nintroduced in SPC-3 revision 1 and thus is applicable to all SCSI devices. In practice it  is\nused  mainly for tape systems. This utility is based on the SPC-5 draft standard, revision 17\n(spc5r17.pdf).\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "Arguments to long options are mandatory for short options as well.\n",
            "subsections": [
                {
                    "name": "-c --cache",
                    "content": "sets the CACHE bit in the READ ATTRIBUTE cdb. This instructs the device server to  re‐\nturn  cached  attributes.  By  default  that bit is cleared which instructs the device\nserver not to return cached attributes.\n",
                    "flag": "-c",
                    "long": "--cache"
                },
                {
                    "name": "-e --enumerate",
                    "content": "enumerates all known attributes and service actions. Attributes include an identifier,\nlength, format and a name as defined by T10. If DEVICE is given then it is ignored.\n",
                    "flag": "-e",
                    "long": "--enumerate"
                },
                {
                    "name": "-E --ea",
                    "content": "where  EA  is an element address which is placed in the READ ATTRIBUTE cdb. This field\nis only found in SMC-2 and SMC-3 drafts for medium changers  usually  associated  with\ntape libraries. By default this field is set to zero.\n",
                    "flag": "-E",
                    "long": "--ea"
                },
                {
                    "name": "-f --filter",
                    "content": "where  FL is an attribute identifier in the range 0 to 65535 or -1.  Attribute identi‐\nfiers are typically given in hexadecimal in which case the hex number should  be  pre‐\nfixed  by \"0x\" or has a trailing \"h\". \"-1\" is the default value and means 'match all';\nfor all other values of FL on the matching attribute is output.\n",
                    "flag": "-f",
                    "long": "--filter"
                },
                {
                    "name": "-F --first",
                    "content": "where FAI is the \"first attribute identifier\" field in the cdb. It seems as though the\nintent of this field is that only attributes whose identifiers are equal to or greater\nthan FAI are returned. The default value of FAI is zero. Attributes  are  returned  in\nascending identifier order.\n",
                    "flag": "-F",
                    "long": "--first"
                },
                {
                    "name": "-h --help",
                    "content": "output the usage message then exit.\n",
                    "flag": "-h",
                    "long": "--help"
                },
                {
                    "name": "-H --hex",
                    "content": "output  the  response  in  hexadecimal to stdout. When used once the whole response is\noutput in ASCII hexadecimal with a leading address (starting at 0) on each line.  When\nused twice each attribute descriptor in the response is output separately in hexadeci‐\nmal. When used thrice the whole response is output in hexadecimal with no leading  ad‐\ndress (on each line).\nOutput  generated  by  '-HHH' (or --hex used three times) can be redirected to a file.\nThat file will be in suitable format for --in=FN to use in a later invocation.\n",
                    "flag": "-H",
                    "long": "--hex"
                },
                {
                    "name": "-i --in",
                    "content": "FN is treated as a file name (or '-' for stdin) which contains  ASCII  hexadecimal  or\nbinary  representing  the response to a READ ATTRIBUTE command with service action 0x0\n(i.e (fetch) attribute values). When this option is given then DEVICE (if also  given)\nis ignored.\nBy default FN is assumed to contain ASCII hexadecimal arranged as bytes which a space,\ntab or comma delimited. All characters from (and including) \"#\" to the end of line are\nignored.  If the --raw option is also given then FN is assumed to contain binary data.\nWhen the --raw option is given then after processing the input the internal raw  vari‐\nable is reset to 0 so it has no effect on the output.\nSince  the  READ ATTRIBUTE response does not contain the service action number that it\nis a response to, then the --sa=SA should be given (if not service action 0 (attribute\nvalues) is assumed.\n",
                    "flag": "-i",
                    "long": "--in"
                },
                {
                    "name": "-l --lvn",
                    "content": "where  LVN  is  placed  in  the \"logical volume number\" field of the cdb.  The default\nvalue is zero which is required to be the logical volume number if the device only has\none volume.\n",
                    "flag": "-l",
                    "long": "--lvn"
                },
                {
                    "name": "-m --maxlen",
                    "content": "where  LEN is the (maximum) response length in bytes. It is placed in the cdb's \"allo‐\ncation length\" field. If not given (or LEN is zero) then 8192 is used. The maximum al‐\nlowed value of LEN is 1048576.\n",
                    "flag": "-m",
                    "long": "--maxlen"
                },
                {
                    "name": "-p --pn",
                    "content": "where  PN is placed in the \"partition number\" field of the cdb. If the DEVICE only has\none partition then its partition number must be zero. The default value of PN is zero.\n",
                    "flag": "-p",
                    "long": "--pn"
                },
                {
                    "name": "-q --quiet",
                    "content": "this option reduces the amount of information  output.  For  example  when  used  once\n(SA=0),  it  suppresses the header line announcing the output of attributes; when used\ntwice it suppresses the name of each attribute, leaving only the associated  attribute\nvalues (or strings).\n",
                    "flag": "-q",
                    "long": "--quiet"
                },
                {
                    "name": "-r --raw",
                    "content": "output the SCSI response (i.e. the data-out buffer) in binary (to stdout).\n",
                    "flag": "-r",
                    "long": "--raw"
                },
                {
                    "name": "-R --readonly",
                    "content": "open  the  DEVICE  read-only (e.g. in Unix with the ORDONLY flag).  The default is to\nopen it read-write.\n",
                    "flag": "-R",
                    "long": "--readonly"
                },
                {
                    "name": "-s --sa",
                    "content": "where SA is placed on the \"service action\" field of the cdb. Values of 0 to 63 are ac‐\ncepted with a default of 0. spc5r08.pdf defines five service actions: 0 for attributes\nvalues ; 1 for an attribute list (names, not values), 2 for the logical volume list; 3\nfor  the  partition list; 4 is restricted for SMC-3; and 5 for the supported attribute\nlist.\nAlternatively an acronym can be given for SA. The acronym should be one of \"av\", \"al\",\n\"lvl\",  \"pn\",  \"smc\" or \"sa\" for service actions 0 to 5 respectively. The acronyms can\nalso be given in upper case.\n",
                    "flag": "-s",
                    "long": "--sa"
                },
                {
                    "name": "-v --verbose",
                    "content": "increase the level of verbosity, (i.e. debug output).\n",
                    "flag": "-v",
                    "long": "--verbose"
                },
                {
                    "name": "-V --version",
                    "content": "print the version string and then exit.\n",
                    "flag": "-V",
                    "long": "--version"
                }
            ]
        },
        "NOTES": {
            "content": "Only tape systems seem to implement the SCSI READ ATTRIBUTE command. The vast majority of its\ndefinition is in the SPC standard so other device types could use it.\n\nMuch of the information provided by READ ATTRIBUTE can also be found in pages returned by LOG\nSENSE (see the sglogs utility) and in the VPD pages returned by the INQUIRY command.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "To list the attributes of a tape drive whose DEVICE is /dev/sg1  ,  the  following  could  be\nused:\n\n# sgreadattr -s al /dev/sg1\nAttribute list:\nRemaining capacity in partition [MiB]\nMaximum capacity in partition [MiB]\nTapeAlert flags\nLoad count\nMAM space remaining [B]\nAssigning organization\nFormat density code\n...\n\nTo check the number of partitions:\n\n# sgreadattr -s pl /dev/sg1\nPartition number list:\nFirst partition number: 0\nNumber of partitions available: 2\n\nAnd to see the attribute values (which is the default service action):\n\n# sgreadattr /dev/sg1\nAttribute values:\nRemaining capacity in partition [MiB]: 1386103\nMaximum capacity in partition [MiB]: 1386103\nTapeAlert flags: 0\n....\n\nTo redirect the attribute values response to a file for later decoding:\n\n# sgreadattr -HHH /dev/sg1 > av.hex\n\nAnd later the response held in the av.hex file could be decoded with:\n\n# sgreadattr -s av --in=av.hex\nAttribute values:\nRemaining capacity in partition [MiB]: 1386103\nMaximum capacity in partition [MiB]: 1386103\nTapeAlert flags: 0\n....\n",
            "subsections": []
        },
        "EXIT STATUS": {
            "content": "The  exit  status  of sgreadattr is 0 when it is successful. Otherwise see the sg3utils(8)\nman page.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Written by Douglas Gilbert.\n",
            "subsections": []
        },
        "REPORTING BUGS": {
            "content": "Report bugs to <dgilbert at interlog dot com>.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright © 2016-2020 Douglas Gilbert\nThis software is distributed under a FreeBSD license. There is NO warranty; not even for MER‐\nCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "sgvpd,sglogs(sg3utils)\n\n\n\nsg3utils-1.46                              December 2020                            SGREADATTR(8)",
            "subsections": []
        }
    },
    "summary": "sgreadattr - send SCSI READ ATTRIBUTE command",
    "flags": [
        {
            "flag": "-c",
            "long": "--cache",
            "arg": null,
            "description": "sets the CACHE bit in the READ ATTRIBUTE cdb. This instructs the device server to re‐ turn cached attributes. By default that bit is cleared which instructs the device server not to return cached attributes."
        },
        {
            "flag": "-e",
            "long": "--enumerate",
            "arg": null,
            "description": "enumerates all known attributes and service actions. Attributes include an identifier, length, format and a name as defined by T10. If DEVICE is given then it is ignored."
        },
        {
            "flag": "-E",
            "long": "--ea",
            "arg": null,
            "description": "where EA is an element address which is placed in the READ ATTRIBUTE cdb. This field is only found in SMC-2 and SMC-3 drafts for medium changers usually associated with tape libraries. By default this field is set to zero."
        },
        {
            "flag": "-f",
            "long": "--filter",
            "arg": null,
            "description": "where FL is an attribute identifier in the range 0 to 65535 or -1. Attribute identi‐ fiers are typically given in hexadecimal in which case the hex number should be pre‐ fixed by \"0x\" or has a trailing \"h\". \"-1\" is the default value and means 'match all'; for all other values of FL on the matching attribute is output."
        },
        {
            "flag": "-F",
            "long": "--first",
            "arg": null,
            "description": "where FAI is the \"first attribute identifier\" field in the cdb. It seems as though the intent of this field is that only attributes whose identifiers are equal to or greater than FAI are returned. The default value of FAI is zero. Attributes are returned in ascending identifier order."
        },
        {
            "flag": "-h",
            "long": "--help",
            "arg": null,
            "description": "output the usage message then exit."
        },
        {
            "flag": "-H",
            "long": "--hex",
            "arg": null,
            "description": "output the response in hexadecimal to stdout. When used once the whole response is output in ASCII hexadecimal with a leading address (starting at 0) on each line. When used twice each attribute descriptor in the response is output separately in hexadeci‐ mal. When used thrice the whole response is output in hexadecimal with no leading ad‐ dress (on each line). Output generated by '-HHH' (or --hex used three times) can be redirected to a file. That file will be in suitable format for --in=FN to use in a later invocation."
        },
        {
            "flag": "-i",
            "long": "--in",
            "arg": null,
            "description": "FN is treated as a file name (or '-' for stdin) which contains ASCII hexadecimal or binary representing the response to a READ ATTRIBUTE command with service action 0x0 (i.e (fetch) attribute values). When this option is given then DEVICE (if also given) is ignored. By default FN is assumed to contain ASCII hexadecimal arranged as bytes which a space, tab or comma delimited. All characters from (and including) \"#\" to the end of line are ignored. If the --raw option is also given then FN is assumed to contain binary data. When the --raw option is given then after processing the input the internal raw vari‐ able is reset to 0 so it has no effect on the output. Since the READ ATTRIBUTE response does not contain the service action number that it is a response to, then the --sa=SA should be given (if not service action 0 (attribute values) is assumed."
        },
        {
            "flag": "-l",
            "long": "--lvn",
            "arg": null,
            "description": "where LVN is placed in the \"logical volume number\" field of the cdb. The default value is zero which is required to be the logical volume number if the device only has one volume."
        },
        {
            "flag": "-m",
            "long": "--maxlen",
            "arg": null,
            "description": "where LEN is the (maximum) response length in bytes. It is placed in the cdb's \"allo‐ cation length\" field. If not given (or LEN is zero) then 8192 is used. The maximum al‐ lowed value of LEN is 1048576."
        },
        {
            "flag": "-p",
            "long": "--pn",
            "arg": null,
            "description": "where PN is placed in the \"partition number\" field of the cdb. If the DEVICE only has one partition then its partition number must be zero. The default value of PN is zero."
        },
        {
            "flag": "-q",
            "long": "--quiet",
            "arg": null,
            "description": "this option reduces the amount of information output. For example when used once (SA=0), it suppresses the header line announcing the output of attributes; when used twice it suppresses the name of each attribute, leaving only the associated attribute values (or strings)."
        },
        {
            "flag": "-r",
            "long": "--raw",
            "arg": null,
            "description": "output the SCSI response (i.e. the data-out buffer) in binary (to stdout)."
        },
        {
            "flag": "-R",
            "long": "--readonly",
            "arg": null,
            "description": "open the DEVICE read-only (e.g. in Unix with the ORDONLY flag). The default is to open it read-write."
        },
        {
            "flag": "-s",
            "long": "--sa",
            "arg": null,
            "description": "where SA is placed on the \"service action\" field of the cdb. Values of 0 to 63 are ac‐ cepted with a default of 0. spc5r08.pdf defines five service actions: 0 for attributes values ; 1 for an attribute list (names, not values), 2 for the logical volume list; 3 for the partition list; 4 is restricted for SMC-3; and 5 for the supported attribute list. Alternatively an acronym can be given for SA. The acronym should be one of \"av\", \"al\", \"lvl\", \"pn\", \"smc\" or \"sa\" for service actions 0 to 5 respectively. The acronyms can also be given in upper case."
        },
        {
            "flag": "-v",
            "long": "--verbose",
            "arg": null,
            "description": "increase the level of verbosity, (i.e. debug output)."
        },
        {
            "flag": "-V",
            "long": "--version",
            "arg": null,
            "description": "print the version string and then exit."
        }
    ],
    "examples": [
        "To list the attributes of a tape drive whose DEVICE is /dev/sg1  ,  the  following  could  be",
        "used:",
        "# sgreadattr -s al /dev/sg1",
        "Attribute list:",
        "Remaining capacity in partition [MiB]",
        "Maximum capacity in partition [MiB]",
        "TapeAlert flags",
        "Load count",
        "MAM space remaining [B]",
        "Assigning organization",
        "Format density code",
        "...",
        "To check the number of partitions:",
        "# sgreadattr -s pl /dev/sg1",
        "Partition number list:",
        "First partition number: 0",
        "Number of partitions available: 2",
        "And to see the attribute values (which is the default service action):",
        "# sgreadattr /dev/sg1",
        "Attribute values:",
        "Remaining capacity in partition [MiB]: 1386103",
        "Maximum capacity in partition [MiB]: 1386103",
        "TapeAlert flags: 0",
        "....",
        "To redirect the attribute values response to a file for later decoding:",
        "# sgreadattr -HHH /dev/sg1 > av.hex",
        "And later the response held in the av.hex file could be decoded with:",
        "# sgreadattr -s av --in=av.hex",
        "Attribute values:",
        "Remaining capacity in partition [MiB]: 1386103",
        "Maximum capacity in partition [MiB]: 1386103",
        "TapeAlert flags: 0",
        "...."
    ],
    "see_also": [
        {
            "name": "sglogs",
            "section": "sg3utils",
            "url": "https://www.chedong.com/phpMan.php/man/sglogs/sg3utils/json"
        }
    ]
}