Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux common lookup commands

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Whereis command

Simple and fast method

$whereis ls

You can search for the "ls" command and its online help documentation location. Because whereis is queried in a database (/ var/lib/mlocate/), whereis queries are fast. This database is created automatically by the Linux system, contains all the local file information, and is updated daily by automatically executing the updatedb command. Because the database is updated once a day, whereis may not be able to search for newly added files, and if you need more accurate results, you need to execute updatedb manually first.

Locate command

Locate is similar to whereis, using the same database, but locate has a more complex matching syntax.

$locate ls

It will match the "ls" files that have appeared in either the file name or the path, but sometimes there are too many, requiring a precise search, you can:

$locate-b "\ ls"

But locate and whereis have the same shortcomings. For speed, accuracy needs to be sacrificed.

Which command

Common search commands

$which gcc

It simply searches the path specified in the $PATH environment variable for the location of the executable, which is typically used to determine whether the specified software is installed. As in the above example, if gcc is installed, the path of the gcc program will be returned, otherwise an error will be reported.

Find command

The most powerful command, find lookup is very time-consuming, but the most accurate.

Find

< path >

< expression >

< cmd >

Path: the directory to search for and all its subdirectories. The default is the current directory

Experssion: characteristics of the file to be searched

Cmd: specific processing of search results

Common options and examples of find

-name looks for files by file name

$find / dir-name filename

$find. -name filename # current directory and its subdirectories (with "." Represents)

-perm finds files according to file permissions

$find. -perm 644

Grep command

A powerful text search tool that uses regular expressions to search for text and print matching lines.

one

Grep [option] pattern [file name]

Options and parameters:

-a: search binary files for data in the form of text files

-c: calculates the number of times a 'search string' is found

-I: ignore the case difference, so the case is considered the same

-n: output the line number by the way

-v: reverse selection, that is, the line that shows no 'search string' content

Pattern is the string to be matched

Grep is generally used in conjunction with pipelines, which is very easy to use!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report