look command in Linux with Examples
The look command in Linux is used to display lines that begin with a specified string. It is especially useful for searching through large files or lists, as it helps you locate entries efficiently. By default, the look command performs case-insensitive matches and searches for exact prefixes. The look command in Linux shows the lines beginning with a given string. This command also uses binary search if the file is sorted. If the file is not specified, the file "/usr/share/dict/words" is used. Then only the alphanumeric characters are compared and the case of alphabetic characters is ignored.
Syntax
look [OPTION]... STRING [FILE]
where,
- STRING: The string that you want to search for.
- FILE (optional): The file in which the search is to be performed. If no file is specified, it searches through the system's dictionary by default.
Basic Example

Commonly Used Options with the look Command
Option | Description |
---|---|
-f, --ignore-case | Ignore case distinctions |
-d, --alphanum | Search using only alphanumeric characters |
-t, --terminate | Limit search by specifying a termination character |
--version | Display version information |
1. -[string]:
This option is used to search for the given string in a specified file.
Example:
look "include" Assignment.c

2. -f:
This option is used to ignore case of alphabetic character.
Example:
look -f ab words

3. -t:
This option is used to specify a string termination character, i.e., only the characters in string up to and including the first occurrence of character are compared.
Example:
look -t b abu words

4. -d:
This option is used to compare only alphanumeric characters.
Example:
look -d ab words

5. -h:
This option is used to show the help message and exit.
Example:
look -h

6. -V:
This option is used to show the version information and exit.
Example:
look -V

Conclusion
The look command is a powerful tool for quickly searching through large files or lists for lines that begin with a specified string. It provides options to make searches case-insensitive, limit the search scope, or focus on alphanumeric characters. Whether you're working with dictionaries or custom files, look can be a valuable utility in your Linux command-line toolkit.