The strings Command

The strings command returns each string of printable characters in files. Its main uses are to determine the contents of and to extract text from binary files (i.e., non-text files).

Characters are the basic symbols that are used to write or print a language. For example, the characters used by the English language consist of the letters of the alphabet, numerals, punctuation marks and a variety of symbols (e.g., the ampersand, the dollar sign and the arithmetic symbols). Printable characters are those which actually display on a monitor screen, as opposed to those that perform other functions, such as indicating a new line or a tab. A string is any finite sequence of characters, and it can be as few as one character.

The basic syntax of the strings command is

strings [options] file_name(s)

When used without any options, strings displays all strings that are at least four characters in length in the files whose names are supplied as arguments (i.e., input data). Strings that are on separate lines in the input files are shown on separate lines on the screen, and an attempt is made to display all strings found on a single line in a file on a single line on the screen (although there may be a carryover to subsequent lines in the event that numerous strings are found on a single line).

Perhaps the most commonly used of strings's few options is -n, which, when followed by an integer, tells it to return strings which are at least the number of that integer in length. For example, the following would display all strings in the files named file1 and file2 that consist of at least two characters:

strings -n 2 file1 file2

The -t option tells strings to also return the offset position for each line on which one or more strings are found. This option is followed by a letter indicating the numbering system to be used, i.e., o for octal, d for decimal and x for hexadecimal. Each printing character, each space and the start of each new line add one to the count. Thus, for example, for a file named file3 which contains the string abcd followed by a single space and then by the string efghi on the first line and the string jklm on the second line, the following command would return the number 0 before the strings in the first line and the number 11 before the string in the second line:

strings -t d file3

The -f option tells strings to begin each line of its output with the name of the file from which it is returning a particular string, followed by a colon and then by several spaces. This can be useful when simultaneously searching for strings in multiple files.

Created January 26, 2006.
Copyright © 2006 The Linux Information Project. All Rights Reserved.