In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "Linux how to use the locate command to find data and find specified files", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Linux how to use the locate command to find data and find specified files" bar!
The locate command is one of the Linux search commands, which can be used to find data, which is similar to the find command, but the find command consumes more resources. The following editor will introduce the usage of the locate command in detail.
Locate allows users to quickly search for specified files in the file system. The method is to first establish a database that includes all the file names and paths in the system, and then when looking for it, you only need to query the database without actually going deep into the file system. In the general distribution, the establishment of the database is automatically executed in crontab.
1. Command format:
Locate [Select parameters] [style]
2. Command function:
The locate command can quickly find the files when searching the database, which is updated by the updatedb program, and the updatedb is established periodically by cron daemon. The locate command searches the database faster than the whole hard disk data, but the worse thing is that the files found by locate may not be found if they are recently created or renamed. In the default value, updatedb will run once a day. The setting value can be updated by modifying the crontab. (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
Thank you for your reading, the above is the content of "Linux how to use the locate command to find data and find specified files". After the study of this article, I believe you have a deeper understanding of how Linux uses the locate command to find data and find specified files, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.