strings Command
Purpose
Finds the printable strings in a file.
Syntax
strings [ -a ] [ - ] [ -o ] [ -t Format ] [ -n Number ] [ -Number ] [ File ... ]
Description
The strings command looks for printable strings in a file. A string is any sequence of 4 or more printable characters that end with a new-line or a null character. The strings command is useful for identifying random object files.
Flags
| Item | Description |
|---|---|
| -a or - | Searches the entire file, not just the data section, for printable strings. If this flag is omitted, the strings command only looks in the initialized data space of object files. |
| -n Number | Specifies a minimum string length other than the default of 4 characters. The maximum value of a string length is 4096. This flag is identical to the -Number flag. |
| -o | Lists each string preceded by its octal offset in the file. This flag is identical to the -t o flag. |
| -t Format | Lists each string preceded by its offset from the start of
the file. The format is dependent on the character used as the Format variable.
Note: When the -o and the -t Format flags are defined more than once on a command line, the last flag specified controls the behavior of the strings command. |
| -Number | Specifies a minimum string length other than the default of 4 characters. The maximum value of a string length is 4096. This flag is identical to the -n Number flag. |
| File | Binary or object file to be searched. |
Exit Status
This command returns the following exit values:
| Item | Description |
|---|---|
| 0 | Specifies that the command ran successfully. |
| >0 | Specifies that an error occurred. |
Examples
- To search a file,
enter:
The string command displays:strings strings@(#)56 1.17 com/cmd/scan/strings.c, cdmscan, bos320 5/7/92 10:21:20 Standard input strings.cat /usr/mbin/strings Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] %7o %7d %7x %7o %7d - To search for strings
at least 12 characters long, enter:
The string command displays:strings -12 strings1.17 com/cmd/scan/strings.c, cdmscan, bos320 5/7/92 10:21:20 Standard input /usr/mbin/strings Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] - To search for strings
at least 20 characters long and show the offset in hexadecimal, enter:
The string command displays:strings -t x -n 20 strings1017 1.17 com/cmd/scan/strings.c, cmdscan, bos320 5/7/92 10:21:20 108c Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] 10d8 Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] 1124 Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] 1170 Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...] 11bc Usage: strings [-a | -] [-o] [-t format] [-n | -#] [file...]