look命令

look命令用于查询单词,仅需指定欲查询的字首字符串,它会显示所有开头字符串符合该条件的单词。

语法

look [-bdf] [-t char] string [file ...]

参数

示例

使用look查找以ab开头的单词。

look ab
# Abbas
# Abbas's
# Abbasid
# Abbasid's
# Abbott
# Abbott's
# Abby
# ...

在文件中查找以L开头的单词并列出全句。

# file.txt
HELLO LINUX!  
Linux is a free unix-type opterating system.  
This is a linux testfile!  
look L file.txt
Linux is a free unix-type opterating system.

在上述示例中使用-t指定字符串终止字符,即仅比较字符串中第一次出现之前(包括第一次出现)的字符。

look -t E HEO file.txt
# HELLO LINUX!

参考

https://www.runoob.com/linux/linux-comm-look.html
https://www.tutorialspoint.com/unix_commands/look.htm
https://www.geeksforgeeks.org/look-command-in-linux-with-examples/