This tutorial explains Linux “look” command, options and its usage with examples.
The look utility displays any lines in file which contain string as a prefix. As look performs a binary search, the lines in file must be sorted (where sort got the same options -d and/or -f that look is invoked with).
If file is not specified, the file /usr/share/dict/words is used, only alphanumeric characters are compared and the case of alphabetic characters is ignored.
look [-dfab ] [-t termchar ] string [file ]
Use binary search
Dictionary character set and order, i.e. only alphanumeric characters are compared.
Ignore the case of alphabetic characters.
Use the alternate dictionary /usr/share/dict/web2
Specify a string termination character, i.e. only the characters in string up to and including the first occurrence of termchar are compared.
1. A Basic Example
Suppose you want to verify the spelling of the word rendezvous. You can do it easily using look command.
$ look rendez rendezvous rendezvous's rendezvoused rendezvouses rendezvousing
2. Searching for a string in a file
For example, if I want to display all the header files that are included in a c file, I’d use the look command in the following way :
$ look "#include" test.c #include <stdio.h> #include <stdlib.h>
3. Ignoring case while searching
When you want to know the spelling of a word which has the prefix ‘excl’.
$ look excl myfile exclaimed exclamation
This displays the word that starts with the given prefix (case sensitive) from file myfile.
$ look -f excl myfile exclaimed exclamation EXCLAMATORY
4. Use Binary Search
$ look -bf excl myfile exclaimed exclamation EXCLAMATORY
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.