Skip to content

look Linux Command Guide

The Linux look command is a helpful tool for finding lines in a sorted file that start with a specific keyword. By specifying a keyword, look will search for and display any lines that match the provided criteria. This command is useful for quickly locating relevant information in large files and can be combined with other commands for more complex searches. The look command is simple to use and can save you time when working with sorted files in Linux.

Terminal window
look [OPTION] STRING [FILE]
OptionDescription
-bIgnore leading blanks
-fFold lower case to upper case
-tStop after the first matching line
ParameterDescription
STRINGThe string to search for in the file
FILEThe file to search for the specified string
Terminal window
look "example" file.txt

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

Terminal window
look "prefix" file.txt

Displays lines in the file “file.txt” that start with the prefix “prefix”.

Terminal window
look -f "example" file.txt

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

Terminal window
look "[0-9][0-9]*" file.txt

Displays lines in the file “file.txt” that match the pattern of one or more digits at the beginning.

Terminal window
look -b "first" "second" file.txt

Displays lines containing both “first” and “second” in the file “file.txt”.

Terminal window
look -x "exact" file.txt

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

Terminal window
look "ls" $PATH

Locates the command “ls” in the system’s PATH directories.

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

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

The look command in Linux is used to search for lines that begin with a specific word from a sorted file.

Section titled “How can I make the look command perform a case-insensitive search?”

To make the look command perform a case-insensitive search, use the -f (ignore case) option. Here’s an example:

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

How can I display a specific number of lines after a match using look?

Section titled “How can I display a specific number of lines after a match using look?”

To display a specific number of lines after a match while using look, you can pipe the output to the tail command. For example:

Terminal window
look word /usr/share/dict/words | tail -n 5

Can I use regular expressions with the look command in Linux?

Section titled “Can I use regular expressions with the look command in Linux?”

No, the look command in Linux does not support regular expressions. It only performs prefix matching on the lines of the input file.

How can I get the version information of the look command?

Section titled “How can I get the version information of the look command?”

To get version information of the look command, you can use the --version option. Here’s how you can do it:

Terminal window
look --version
  • Finding words in a sorted dictionary
  • Searching for specific terms in a large text file
  • Locating keywords in configuration files
  • Identifying patterns in datasets
  • Checking for the presence of particular strings in a file