Linux study notes fifth day - common search commands

I'm a little irritable, I don't want to write, I can't do it, I can't help but study, I'm annoying!

1 locate Quick Find

Format: locate name.

locate can quickly find the content you want to find. Unlike find, locate does not traverse to the destination location, but searches in the file database, which greatly reduces the search time and can basically achieve second search.

eg:locate clj* is to find files and directories starting with clj, and the search speed is very fast.

We can take a look at this file repository (locate locate)

The circled part is the file repository. The file database is automatically updated so we can find it quickly. However, look at the following command

I saw a file under root. When I used locate to search for it, I found that I couldn't find it, because at this time, the new file you created has not been updated to the file database, so you can't find it. , at this time, you need to manually update: updatedb, so that you can query again. But one thing to note is that the files in the temporary directory will not be included in the file database , that is to say, you cannot find the contents of the directory where the temporary files are stored by using locate.

which (query where the command file is located)

eg: which ls is the location of the query ls command

whereis (where the query command file is located)

The functions of whereis and which are the same, but whereis finds more things than which, and it also displays the help file of the command

grep

grep is a very common command. It can search in the file content. For example, I search for the content of profinet in services: grep -i profinet /etc/services, the function of this -i is case-insensitive, without -i, it will be case-sensitive

In addition, you can also use -v to query the content that does not include certain content, this sentence is a bit messy, just look at the command directly

grep -v ^# /etc/inittab (^# means starting with a pound sign) is to find the content that does not start with # in the inittab file.

ok!

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325017640&siteId=291194637