In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Detailed explanation of find command
We have more or less used windows file lookup, for the entire file system, part of the partition, to the file name, time and other conditions to find files. In Linux, two commands, locate and find, are used to complete the file search.
First of all, let's briefly talk about the adaptation scenarios and respective characteristics of the locate and find commands. Both locate and find can find qualified files based on file system in Linux, but they have their own characteristics and usage scenarios. The locate command implements file lookup on the file system and is based on a pre-built search database. The locate command searches the database instead of traversing the specified file system for each search, so you can quickly retrieve and find files that meet the criteria.
Locate command search is to find the database, some files in the database, can be quickly found, the database has not been updated, can not be found, so through the locate command to find files, is not real-time search, the recently created files have not established a relevant index in the database and other information, can not be found.
Locate has two ways to update the search database:
1. The planned task set by the system, search and traverse the entire root file system, and automatically complete the update of the database
2. Updatedb command to update the database manually
Therefore, the locate command is suitable for non-real-time, fuzzy, fast lookups.
The basic usage of the locate command:
Locate [option]... [pattern]...
Common options:
-h help information
-I ignore case
-c count the number of documents that meet the criteria
-b displays only the base name in the matching path
-r supports using regular expressions to match pattern
Generally, in Linux, the locate command is used to find files less, but more find commands are used to achieve real-time and accurate file search.
Detailed explanation of find command
The find search command, which completes the search by traversing the specified file system and matching the search pattern, is a real-time and accurate search.
The basic usage of the find command:
Find [option]... [find file path] [find condition] [processing action after search]
Common options: generally use less
Find file path: find the starting path of the file. The default is the current working directory.
Search criteria: the specified search criteria can be file name, file size, file type, permissions, dependencies, timestamps and other criteria. The default is to find all files under the specified path.
Processing action: operate on files that meet the criteria, which defaults to standard output.
Note: find looks for files. The default is glob file name wildcard, rather than regular metacharacter wildcard.
Search criteria:
-name "pattern" looks for files by file name
-iname "pattern" looks for files based on file names, ignoring case
Example:
# find / etc-name pass* # look for files whose names begin with pass in the / etc directory
# find /-name pass* # look for files whose names begin with pass in the root directory
-regex "pattern" search based on regular expression matching
Less used in find, regular expressions work in greedy mode, matching the entire path rather than the base name
-user username finds files owned by the specified user
-group groupname finds files that belong to the specified group
-uid UID finds the file whose owner is the specified UID
-gid GID finds files with the specified GID in the attribute group
-nouser looks for files without owners
-nogroup looks for files that do not belong to a group
Combined testing:
And:-a default combinational logic
Or:-o
Non:-not or!
Note: if you use parentheses when combining tests, you need to escape\ (\)
-type TYPE looks up according to file type
F ordinary files d directories l link files b block devices c character device files p pipes s sockets
-size [+ | -] # units search based on file size
Commonly used units: k M G
Note:-size 3M: the files found are files that meet the range of less than 4m and greater than 2m.
-size + 3m: looking for files of 4m and greater
-size-3m: looking for files of 2m and less than 2m
Find according to the timestamp
In days
-atime [+ | -] #
-mtime [+ | -] #
-ctime [+ | -] #
Divided into units
-amin [+ | -] #
-mmin [+ | -] #
-cmin [+ | -] #
Example: # find / etc-mtime-7 # find files that have been modified within 7 days
Find based on permissions
-perm [/ | -] mode
Note:-perm mode: exact matching weight limit
-perm / mode: any permission bit of any type of user (umeme gpeno), any one of which satisfies the condition (as long as one of the 9 permission bits is satisfied, the logical relationship of yes or)
-perm-mode: every bit of the permission bit of each type of user (uMagazine gpeno). If the condition is met at the same time, it is satisfied (the logical relationship between the 9 permission bits is and).
Example: # find / etc-not-perm / 222-type f # find files for which all users do not have write permission
Processing actions:
-print output to standard output, default action
-ls is similar to executing the "ls-l" command on the found file, outputting the details of the file
-delete deletes the found file
-fls / path/to/file saves the long format information of all found files to the specified file
-ok command {}\; each file found is handed over to command for execution, and each file execution requires user confirmation.
-exec command {}\; each file found is handed over to command to execute without user confirmation
Note: the file path found by find is passed to the following command, which is to find out all the file paths that meet the criteria and pass them to the following command at one time. However, some command cannot accept long parameters, and command execution will fail. There is another way to get around this problem: # find... | xargs command
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.