{"id":4183,"date":"2018-05-29T12:28:23","date_gmt":"2018-05-29T08:28:23","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-strings-command\/"},"modified":"2018-05-29T12:28:23","modified_gmt":"2018-05-29T08:28:23","slug":"linux-strings-command-tutorial-for-beginners-5-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-strings-command-tutorial-for-beginners-5-examples\/","title":{"rendered":"Linux strings Command Tutorial for Beginners (5 Examples)"},"content":{"rendered":"<p>Looking inside a binary\/executable file to grab human-readable strings isn&#8217;t the kind of work that everybody does, but what if you are asked to do this? Opening the file in an editor, and manually looking for stuff isn&#8217;t an elegant solution. So, what to do? Yes, you guessed it right &#8211; there exists a command line utility that does this for you.<\/p>\n<p>The tool in question is dubbed <strong>Strings<\/strong>, and in this tutorial, we will discuss the basics of this command using some easy to understand examples. But before we do that, it&#8217;s worth mentioning that all examples in this article have been tested on Ubuntu 16.04 LTS machine.<\/p>\n<h2 id=\"linux-strings-command\">Linux Strings command<\/h2>\n<p>The Strings command basically prints the strings of printable characters in files. Following is its syntax:<\/p>\n<p class=\"command\">strings [OPTIONS] FILENAME<\/p>\n<p>And here&#8217;s how the tool&#8217;s man page describes it:<\/p>\n<pre readability=\"17\"> For each file given, GNU strings prints the printable character<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sequences that are at least 4 characters long (or the number given with<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 the options below) and are followed by an unprintable character.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Depending upon how the strings program was configured it will default<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 to either displaying all the printable sequences that it can find in<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 each file, or only those sequences that are in loadable, initialized<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 data sections.\u00a0 If the file type in unrecognizable, or if strings is<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 reading from stdin then it will always display all of the printable<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sequences that it can find.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 For backwards compatibility any file that occurs after a command line<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 option of just - will also be scanned in full, regardless of the<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 presence of any -d option.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 strings is mainly useful for determining the contents of non-text<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 files.<\/p><\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a good idea on how the Strings command works.<\/p>\n<h2 id=\"q-how-to-use-strings-command\">Q1. How to use strings command?<\/h2>\n<p>Basic usage is fairly easy &#8211; just pass the file name as input and execute the command.<\/p>\n<p><em>Please note that since Strings is mainly used to extract info from binary\/executable files, we&#8217;ll use one such file in all our examples.<\/em><\/p>\n<p>For example:<\/p>\n<p class=\"command\">strings test<\/p>\n<p>Here&#8217;s the output this command produced on my system:<\/p>\n<p><a class=\"fancybox\" id=\"img-strings-basic\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/strings-basic.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/linux-strings-command-tutorial-for-beginners-5-examples.png\" alt=\"How to use strings command\" width=\"300\" height=\"445\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-force-a-custom-character-limit\">Q2. How to force a custom character limit?<\/h2>\n<p>As explained in the beginning, the default behavior of the Strings tool is to only print character sequences that are at least 4 characters long. However, if you want, you can change this limit using the -n command line option (which requires you to pass a number that signifies the new limit).<\/p>\n<p>For example, If you want to set the limit to 2, following is how you can do this:<\/p>\n<p class=\"command\">strings -n 2 test<\/p>\n<p><a class=\"fancybox\" id=\"img-strings-n-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/strings-n-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/linux-strings-command-tutorial-for-beginners-5-examples-1.png\" alt=\"How to force a custom character limit\" width=\"200\" height=\"434\" title=\"\"><\/a><\/p>\n<p>So now you can see two and three character strings in the output as well.<\/p>\n<h2 id=\"q-how-to-make-strings-print-offset-of-character-sequences\">Q3. How to make strings print offset of character sequences?<\/h2>\n<p>If you want Strings to also display the offsets of character sequences it displays in output, then this can be done using the -t command line option, which requires you to provide a single character input that specifies the radix of the offset &#8211; &#8216;o&#8217; for octal,\u00a0 &#8216;x&#8217; for hexadecimal, or &#8216;d&#8217; for decimal.<\/p>\n<p>For example:<\/p>\n<p class=\"command\">strings -t d test<\/p>\n<p>And here&#8217;s the output it produced on my system:<\/p>\n<p><a class=\"fancybox\" id=\"img-strings-o-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/strings-o-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/linux-strings-command-tutorial-for-beginners-5-examples-2.png\" alt=\"How to make strings print offset of character sequences\" width=\"350\" height=\"314\" title=\"\"><\/a><\/p>\n<p>So you can see the strings in output are now preceded by their respective offsets.<\/p>\n<h2 id=\"q-how-to-make-strings-scan-whole-file\">Q4. How to make Strings scan whole file?<\/h2>\n<p>Depending upon how Strings was configured, it may or may not scan the whole input file. However, if you want to be absolutely sure that the tool reads the complete file (and not just loadable, initialized data sections), use the -a command line option.<\/p>\n<p>For example:<\/p>\n<p class=\"command\">strings -a test<\/p>\n<p>Conversely, if you want Strings to only display strings from initialized, loaded data sections in the file, use the -d command line option.<\/p>\n<p class=\"command\">strings -d test<\/p>\n<h2 id=\"q-how-to-change-the-separator\">Q5. How to change the separator?<\/h2>\n<p>As you&#8217;d have observed, by default, the separator used by Strings is a newline. However, if you want, you can have a custom separator using the -s command line option.<\/p>\n<p>For example:<\/p>\n<p class=\"command\">strings -s [[[]]] test<\/p>\n<p><a class=\"fancybox\" id=\"img-strings-s-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/strings-s-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/linux-strings-command-tutorial-for-beginners-5-examples-3.png\" alt=\"How to change the separator\" width=\"500\" height=\"269\" title=\"\"><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>The Strings command is an extremely useful tool if you are into digging binaries\/executables for useful information. We have discussed some important command line options here. So practice them, and once you&#8217;re done, head to the tool&#8217;s\u00a0<a href=\"https:\/\/linux.die.net\/man\/1\/strings\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a> for more info.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-strings-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/linux-strings-command-tutorial-for-beginners-5-examples-4.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-strings-command%2F&amp;text=Linux+strings+Command+Tutorial+for+Beginners+%285+Examples%29&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/linux-strings-command-tutorial-for-beginners-5-examples-5.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/linux-strings-command-tutorial-for-beginners-5-examples-6.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-strings-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/05\/linux-strings-command-tutorial-for-beginners-5-examples-7.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Looking inside a binary\/executable file to grab human-readable strings isn&#8217;t the kind of work that everybody does, but what if you are asked to do this? Opening the file in an editor, and manually looking for stuff isn&#8217;t an elegant solution. So, what to do? Yes, you guessed it right &#8211; there exists a command &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-4183","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/4183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=4183"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/4183\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=4183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=4183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=4183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}