Strings (Unix): Difference between revisions

Content deleted Content added
m typo fix.
WikiCleanerBot (talk | contribs)
m v2.05b - Bot T13 CW#549 - Fix errors for CW project (Split link)
 
(16 intermediate revisions by 7 users not shown)
Line 1:
{{Short description|Shell command for extracting printable text from a binary file}}
{{lowercase}}
{{distinguish|string (computing)}}
{{one source |date=April 2024}}
{{Infobox software
| name = strings
Line 19 ⟶ 21:
| website =
}}
<code>'''strings'''</code> is a [[Shell (computing)|shell command]] that extracts [[printable character]] [[String (computer science)|strings]] from a [[computer file|file]] {{endash}} which is particular useful for analyzing the content of a [[binary file]]. By definition, a binary file contains data that is not printable text yet a binary file often does contain some printable character text {{endash}} often in relatively short sequences distributed throughout the file. These portions of the binary file can be informative as to what the file contains overall. For a [[text file]], a file containing all printable characters, the command prints the entire file content, and therefore, provides no utility over more commonly used file output commands such as <code>[[cat (Unix)|cat]]</code>.
In [[computer software]], '''strings''' is a program in [[Unix]], [[Plan 9 from Bell Labs|Plan 9]], [[Inferno (operating system)|Inferno]], and [[Unix-like]] [[operating system]]s that finds and prints the strings of printable characters in files. The files can be of regular text files or [[binary files]] such as executables. It can be used on object files and [[core dump]]s. '''strings''' is mainly useful for determining the contents of non-text files.
 
StringsThe arecommand recognized by lookingsearches for sequences of at least 4 (by default) printable characters terminatingthat inend with a [[null-terminated string|NUL character]] but ignores any sequence (that is, [[null-terminatedless than string]]s)a specified length or 4 characters by default. Some implementations provide options for determining what is recognized as a printable character, which is useful for finding non-[[ASCII]] and [[wide character]] text. By default, it only prints theselects strings from the initialized and loaded sections of an object files;file. forFor other types of files, it prints theselects strings from the whole file. But it doesn't make the behavior of [[Cat_(Unix)|cat]] and '''strings''' the same on regular text files. [[Cat_(Unix)|cat]] processes the non printable characters and output it to the terminal but '''strings''' ignore them.
==Overview==
Strings are recognized by looking for sequences of at least 4 (by default) printable characters terminating in a NUL character (that is, [[null-terminated string]]s). Some implementations provide options for determining what is recognized as a printable character, which is useful for finding non-ASCII and wide character text. By default, it only prints the strings from the initialized and loaded sections of object files; for other types of files, it prints the strings from the whole file. But it doesn't make the behavior of [[Cat_(Unix)|cat]] and '''strings''' the same on regular text files. [[Cat_(Unix)|cat]] processes the non printable characters and output it to the terminal but '''strings''' ignore them.
 
The command is available in [[Unix]], [[Plan 9 from Bell Labs|Plan 9]], [[Inferno (operating system)|Inferno]], and [[Unix-like]] systems. It is part of the [[GNU Binary Utilities]] ({{mono|binutils}}), and has been portedimplemented toin other operating systems including [[Microsoft Windows|Windows]].<ref>[[cygwin]]</ref>
Common usage includes piping its output to {{mono|[[grep]]}} and {{mono|[[Fold (Unix)|fold]]}} or redirecting the output to a [[Computer file|file]].<ref>{{cite book
| last = Kiddle
| first = Oliver
| author2 = Jerry Peek
| author3 = Peter Stephenson
| title = From Bash to Z Shell
| year = 2005
| ___location = New York, NY
| publisher = Apress
| isbn = 978-1-590-59376-9
| page = 413
| oclc = 57450917
| url = https://www.apress.com/gp/book/9781590593769}}</ref>
 
It is part of the [[GNU Binary Utilities]] ({{mono|binutils}}), and has been ported to other operating systems including [[Microsoft Windows|Windows]].<ref>[[cygwin]]</ref>
 
==Example==
 
Using ''strings'' to print sequences of characters that are at least 8 characters long (this command prints the system's [[BIOS]] information; should be run as root):
The following command searches the system's [[BIOS]] for strings that are at 8 characters long:
<syntaxhighlight lang="bash">
 
dd if=/dev/mem bs=1k skip=768 count=256 2>[[/dev/null]] | strings -n 8 | less
</syntaxhighlight>
 
==See also==
{{Portal|Free and open-source software}}
* [[{{Annotated link|GNU Debugger]]}}
* [[Cat (Unix)]]
* {{Annotated link|List of POSIX commands}}
* [[{{Annotated link|Paste (Unix)]]}}
* [[GNU Debugger]]
* [[{{Annotated link|Strip (Unix)]]}}
 
==References==
Line 70 ⟶ 57:
[[Category:Inferno (operating system) commands]]
[[Category:String (computer science)]]
 
 
{{unix-stub}}