In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "the usage of locate command in linux". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the usage of the locate command in linux.
1. Command format:
Locate [Select parameters] [style]
2. Command function:
Locate command can quickly find the file when searching the database, the database is updated by updatedb program, updatedb is built periodically by cron daemon, locate command searches the database faster than the entire hard disk data to search for information, but the worse thing is that the file found by locate may not be found if it was recently established or renamed, in the default value, updatedb will run once a day, you can modify the crontab to update the set value. (etc/crontab)
Locate is designated to be used to search for files that meet the criteria. It will store files and directory names in the database to find files or catalogs that meet the criteria of the template style, and can use special characters (such as "*" or "?"). If the template is specified as kcpa*ner, locate will find all files or directories that start with a string of kcpa and end with ner. If the name is kcpartner, if the directory name is kcpa_ner, it will list all files in the directory, including subdirectories.
Locate instruction and find search file function is similar, but locate is through the update program to build an index database of all files and directory information in the hard disk, in the implementation of loacte directly to find the index, the query speed will be faster, the index database is generally managed by the operating system, but you can also directly issue update to force the system to modify the index database immediately.
3. Command parameters:
-e will be excluded from the scope of search.
-1 if it is 1. Then start safe mode. In safe mode, users do not see files that cannot be seen by permissions. This starts to slow down because locate must go to the actual file system to obtain file permission data.
-f exclude specific file systems, for example, we are not reasonable to put files in the proc file system in the database.
-Q quiet mode, no error message is displayed.
-n displays at most n outputs.
-r use the regular expression to do the search condition.
-o specify the name of the data inventory.
-d specify the path to the database
-h display auxiliary message
-V displays the version message of the program
4. Use an example:
Example 1: find all files related to pwd
Command:
Locate pwd
Output:
The code is as follows:
Peida-VirtualBox ~ # locate pwd
/ bin/pwd
/ etc/.pwd.lock
/ sbin/unix_chkpwd
/ usr/bin/pwdx
/ usr/include/pwd.h
/ usr/lib/python2.7/dist-packages/twisted/python/fakepwd.py
/ usr/lib/python2.7/dist-packages/twisted/python/fakepwd.pyc
/ usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.py
/ usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyc
/ usr/lib/syslinux/pwd.c32
/ usr/share/help/C/empathy/irc-join-pwd.page
/ usr/share/help/ca/empathy/irc-join-pwd.page
/ usr/share/help/cs/empathy/irc-join-pwd.page
/ usr/share/help/de/empathy/irc-join-pwd.page
/ usr/share/help/el/empathy/irc-join-pwd.page
Example 2: search all files that start with sh in the etc directory
Command:
Locate / etc/sh
Output:
The code is as follows:
Peida-VirtualBox ~ # locate / etc/sh
/ etc/shadow
/ etc/shadow-
/ etc/shells
Peida-VirtualBox ~ #
Example 3: search for all files starting with m in the etc directory
Command:
Locate / etc/m
Output:
The code is as follows:
Peida-VirtualBox ~ # locate / etc/m
/ etc/magic
/ etc/magic.mime
/ etc/mailcap
/ etc/mailcap.order
/ etc/manpath.config
/ etc/mate-settings-daemon
At this point, I believe you have a deeper understanding of "the use of the locate command in linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.