Skip to content

look MacOS Command Guide

The MacOS look command is a useful tool for searching for strings in a sorted file efficiently. It is designed to quickly locate lines that begin with a specific string or match a given pattern, making it a valuable command for users looking to find specific information within a file. By using the look command, users can streamline their search process and easily locate the data they need. This guide will cover the syntax of the look command, as well as various options that can be used to customize the search. Additionally, examples will be provided to demonstrate how the look command can be used in real-world scenarios.

look Syntax:

Terminal window
look [OPTION]... [STRING] [FILE]...

Options:

OptionDescription
-bIgnore differences in blanks
-fIgnore case differences
-tIgnore leading tabs
-VDisplay version information and exit

Parameters:

ParameterDescription
STRINGSearch for STRING in files
FILEFile(s) to search in

look Command Samples:

Search for a Specific Word in a File

Terminal window
look apple file.txt

Searches for the word “apple” in the file “file.txt”.

Display Words Starting with a Specific Prefix

Terminal window
look supercali /usr/share/dict/words

Displays words starting with the prefix “supercali” from the system dictionary file.

Display Words Ending with a Specific Suffix

Terminal window
look -b ness /usr/share/dict/words

Displays words ending with the suffix “ness” from the system dictionary file.

Terminal window
look -f APPLE file.txt

Performs a case-insensitive search for the word “APPLE” in the file “file.txt”.

Display Full Words Only

Terminal window
look -b -f ^word /usr/share/dict/words

Displays only full words that start with “word” from the system dictionary file.

Search for Exact Word Match

Terminal window
look -b -x fish /usr/share/dict/words

Searches for the exact word “fish” in the system dictionary file.

Display Words from System Dictionary

Terminal window
look /

Displays all words available in the system dictionary.

look FAQ:

How do I use look in MacOS?

To use the look command in MacOS, execute the following command:

Terminal window
look search_word file.txt

How can I search for a word in a file with look in MacOS?

To search for a specific word in a file using look, you can run the following command:

Terminal window
look search_word file.txt

Can I specify a case-insensitive search with look in MacOS?

No, the look command in MacOS is case-sensitive. If you want to perform a case-insensitive search, you can preprocess the file or word to ensure consistent case before using the look command.

How do I display all lines that match the search in MacOS with look?

To display all lines that match the search term in MacOS using look, you can use the -b (before) and -a (after) options together in the command. Here is an example:

Terminal window
look -b -a search_word file.txt

Can I use regular expressions with look in MacOS?

No, the look command in MacOS does not support regular expressions. It performs a simple string comparison to find matches in the specified file.

How do I show lines that do not match the search term in MacOS with look?

You can use the -v option with the look command in MacOS to display lines that do not match the search term. Here is an example:

Terminal window
look -v search_word file.txt

Applications of the look command

  1. Searching for words in a sorted dictionary or word list
  2. Checking for the existence of a specific word within a sorted list