In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Linux file search for detailed explanation
The grep, egrep, and fgrep commands we learned earlier are Linux text lookup commands, which simply match strings, not file lookups.
Common commands for file lookup
1,locate:
Locate is a command to find files in the whole system, but the search of locate is not real-time, inaccurate, a way of fuzzy matching, because this way of file search is based on the system-wide file database, and the database is only updated every night, so it is not real-time search, but this file database can be generated manually, in order to enable us to find files in real time. We can update the database manually.
Command to generate file database: updatedb
Advantages: fast execution of locate command
2,find:
The find command supports real-time lookup, precise lookup, and multiple lookup criteria, but the execution speed of the find command is slow, because the find command traverses all the files in the specified directory to find, so the execution speed is slow.
Usage format:
-> find lookup path lookup standard lookup processing actions after searching
The search path can be omitted, which means that the current directory is found by default.
The search standard defaults to finding all files under the specified path
Find processing action (action), which defaults to output to standard output
(1) find (match) criteria (option):
->-name (strictly case-sensitive lookup) 'filename': makes an exact match of file names
File name wildcard is supported
*-> is used to match any character of any length
?-> used to match a single character
[]-> is used to match any single character within a specified range
->-iname: file name matching is case-insensitive
->-regex: file name lookup based on regular expressions
Format:-regex pattern
->-user: search the file according to its owner
Format:-user username
->-group: search a file according to its group
Format:-group groupname
->-uid: according to uid search, once a user is deleted, the owner of all files previously belonging to that user will become the user's id number
Format:-uid uid
->-gid: according to gid search, once a user's subordinate group is deleted, the subordinate group of all files belonging to the user's basic group will become the user's basic group id number.
Format:-gid gid
->-nouser: find files without owners
->-type: find files by file type
F: ordinary files
D: directory
C: character device
B: block equipment
L: link file
P: plumbing equipment
S: socket device
->-size: find files based on file size
[+ | -] #: + means greater than,-means less than, # indicates numeric size (no + |-equals), and only # indicates precise search.
K stands for KB
M stands for MB
G stands for GB
The rule of size matching: there will be errors in accurate search, but the error is generally less than 1 and less than the value to be matched.
Combination condition lookup, default is logic and relation
->-a: logic and relation
->-o: logic or relationship
->-not: logical non-relational
Exercise:
1. Find files in the / tmp directory that are not directories and are not socket types
2. Find the files in the / tmp/test directory where the owner is neither user1 nor user2
Find files based on timestamps
The time is days:
Format:
->-mtime [+ | -] #: modification time
->-ctime [+ | -] #: change the time
->-atime [+ | -] #: access time
-> # indicates that there is an action on the # th day now, + # indicates that there is an action before the # th day now, and-# indicates that there is an action after the # day from now.
The time is minutes
Format:
->-mmin [+ | -] #: modification time
->-cmin [+ | -] #: change the time
->-amin [+ | -] #: access time
-> # means there is an action from the # minute now, + # means there is an action before the # minute from now, and-# means there is an action after the # minute from now
Find based on permissions
Format:
->-perm MODE: indicates an exact match
->-perm + MODE: if any of the three permissions matches, the condition is met.
->-perm-MODE: this MODE is only eligible if the file permission is fully included.
(2) find the future processing action (action):
Default is-print (shown)
->-ls: displays the details of each file in a form similar to the command ls-l
->-ok:-ok means that every step of the processing action requires user confirmation
Fixed format:-ok COMMAND {}\
Curly braces indicate the file name found by the previous find command
->-the processing action of exec:-exec does not need to be confirmed by the user.
Fixed format:-exec COMMAND {}\
Exercise:
1. Find all the files under the / var directory whose main is root and whose group is mail
2. Find files in the / usr directory that do not belong to root, bin, or student
3. Find the files in the / etc directory that have been modified in the last week and do not belong to root and student users
4. Find the files that have no owners or groups on the current system and have been accessed in the last day, and change them to root.
5. Look for files larger than 1m in the / etc directory and write their filenames to / tmp/etc/largefiles
Xargs method:
6. Find the files in the / etc directory that all users do not have write permission to, and show their details
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.