{"id":5883,"date":"2018-08-02T22:29:28","date_gmt":"2018-08-02T18:29:28","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-look-command\/"},"modified":"2018-08-02T22:29:28","modified_gmt":"2018-08-02T18:29:28","slug":"linux-look-command-tutorial-for-beginners-with-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-look-command-tutorial-for-beginners-with-examples\/","title":{"rendered":"Linux look Command Tutorial for Beginners (with Examples)"},"content":{"rendered":"<p>Although the\u00a0<a href=\"https:\/\/www.howtoforge.com\/tutorial\/linux-find-command\/\" target=\"_blank\" rel=\"noopener noreferrer\">Linux find command<\/a> does a fabulous job for searching on the command line, there may be situations where a dedicated tool may be more convinient. One such case is to find lines in a file that start with a particular word. There exists a command &#8211; dubbed <strong>look<\/strong> &#8211; that does this for you.<\/p>\n<p>In this tutorial, we will discuss this command using some easy to understand examples. But before we do that, it&#8217;s worth mentioning that all examples in the article have been tested on an Ubuntu 18.04 LTS machine.<\/p>\n<h2 id=\"linux-look-command\">Linux look command<\/h2>\n<p>The look command in Linux displays lines beginning with a given string. Following is its syntax:<\/p>\n<p class=\"command\">look [-bdf] [-t termchar] string [file &#8230;]<\/p>\n<p>And here&#8217;s what the man page says about the tool:<\/p>\n<pre readability=\"8\"> The look utility displays any lines in file which contain string as a<br\/>\u00a0\u00a0\u00a0\u00a0 prefix.<p>\u00a0\u00a0\u00a0\u00a0 If file is not specified, the file \/usr\/share\/dict\/words is used, only<br\/>\u00a0\u00a0\u00a0\u00a0 alphanumeric characters are compared and the case of alphabetic charac?<br\/>\u00a0\u00a0\u00a0\u00a0 ters is ignored.<\/p><\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a good idea on how the look command works.<\/p>\n<h2 id=\"q-how-to-use-look-command\">Q1. How to use look command?<\/h2>\n<p>Simple, just provide the word you want to search and the file in which you want to search as inputs to the look command.<\/p>\n<p>Here&#8217;s an example:<\/p>\n<p class=\"command\">look The test.txt<\/p>\n<p>The above command searches for lines beginning with &#8216;The&#8217; in the file &#8216;test.txt&#8217;.<\/p>\n<p>For reference, here&#8217;s the test.txt file:<\/p>\n<p><a class=\"fancybox\" id=\"img-look-basic-usage\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/look-basic-usage.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-look-command-tutorial-for-beginners-with-examples.png\" alt=\"How to use look command\" width=\"500\" height=\"61\" title=\"\"><\/a><\/p>\n<p>And here&#8217;s the output produced:<\/p>\n<p><a class=\"fancybox\" id=\"img-look-usage\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/look-usage.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-look-command-tutorial-for-beginners-with-examples-1.png\" alt=\"look command result\" width=\"498\" height=\"39\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-narrow-down-search-within-given-string\">Q2. How to narrow down search within given string?<\/h2>\n<p>The look command also allows you to narrow down your search by allowing you to provide a terminating character. Here&#8217;s how the man page explains the -t option:<\/p>\n<pre>-t, --terminate termchar<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Specify a string termination character, i.e., only the characters<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 in string up to and including the first occurrence of termchar<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 are compared.<\/pre>\n<p>To test this option, I updated test.txt with a few more lines. Take a look:<\/p>\n<p><a class=\"fancybox\" id=\"img-look-t-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/look-t-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-look-command-tutorial-for-beginners-with-examples-2.png\" alt=\"test text\" width=\"500\" height=\"70\" title=\"\"><\/a><\/p>\n<p>And then executed the following command:<\/p>\n<p class=\"command\">look -t n Fund test.txt<\/p>\n<p>So we are basically asking look to search for lines beginning with the word &#8216;Fund&#8217; but also include those that start with &#8216;Fun&#8217;. And here&#8217;s the output:<\/p>\n<p><a class=\"fancybox\" id=\"img-look-t-output\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/look-t-output.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-look-command-tutorial-for-beginners-with-examples-3.png\" alt=\"How to narrow down search within given string\" width=\"467\" height=\"74\" title=\"\"><\/a><\/p>\n<h2 id=\"q-is-look-search-case-sensitive\">Q3. Is look search case sensitive?<\/h2>\n<p>Yes, it is. For example, if you run the following command (which is same as the one we used in last Q&amp;A, save for the lower case of the first character in the word &#8216;fund&#8217;):<\/p>\n<p class=\"command\">look -t n fund test.txt<\/p>\n<p>No output will be produced.<\/p>\n<p>However, you can force look to ignore case by using the -f option.<\/p>\n<p><a class=\"fancybox\" id=\"img-look-f-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/look-f-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-look-command-tutorial-for-beginners-with-examples-4.png\" alt=\"Is look search case sensitive\" width=\"493\" height=\"89\" title=\"\"><\/a><\/p>\n<h2 id=\"q-what-else-look-can-be-used-for\">Q4. What else look can be used for?<\/h2>\n<p>You can use the look command to search for all words beginning with a set of characters. For example, to see what all words start with the\u00a0character sequence &#8216;love&#8217;, just use the look command in the following way:<\/p>\n<p class=\"command\">look love<\/p>\n<p>Here&#8217;s a sample output:<\/p>\n<p><a class=\"fancybox\" id=\"img-look-words\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/look-words.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-look-command-tutorial-for-beginners-with-examples-5.png\" alt=\"What else look can be used for\" width=\"341\" height=\"544\" title=\"\"><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>So all in all, look is a useful little command line utility that you should be at least aware of, for you never know when it may turn out to be a saviour for you. It doesn&#8217;t offer many command line options, and majority we&#8217;ve already discussed here. To learn more about look, head to its <a href=\"https:\/\/linux.die.net\/man\/1\/look\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a>.<\/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-look-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-look-command-tutorial-for-beginners-with-examples-6.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-look-command%2F&amp;text=Linux+look+Command+Tutorial+for+Beginners+%28with+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\/08\/linux-look-command-tutorial-for-beginners-with-examples-7.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\/08\/linux-look-command-tutorial-for-beginners-with-examples-8.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-look-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-look-command-tutorial-for-beginners-with-examples-9.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Although the\u00a0Linux find command does a fabulous job for searching on the command line, there may be situations where a dedicated tool may be more convinient. One such case is to find lines in a file that start with a particular word. There exists a command &#8211; dubbed look &#8211; that does this for you. [&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-5883","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/5883","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=5883"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/5883\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=5883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=5883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=5883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}