In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use the find command in Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The basic syntax format of find:
Find [find location] [find Standard] [processing Action]
Search location: the default is the current directory. You can specify multiple directories with spaces between them.
Find criteria: find all files in the specified directory by default
Processing action: display to standard output, default is print
Analyze what the search criteria for find can be divided into:
1) File name
-name "file name": search according to the file name. Glob is supported.
-iname "file name", which is looked up according to the file name and is case-insensitive
2) the owner and group of the document
-user "USERNAME": search according to the owner
-group "GROUP": search by group
-uid "UID": search based on UID
-gid "GID": search based on GID
-nouser: find files without owners
-nogroup: find files that do not belong to a group
The code is as follows:
[root@Redhat6 /] # find /-nouser-nogroup # has no owner and no group
/ tmp/user1dir
[root@Redhat6 /] # ls-ld / tmp/user1dir/ # verify whether the file you are looking for meets the requirements. The file does not have a user indicating the owner and group, but it will be represented by an ID number.
Drwxrwxr-x 2 500 500 4096 Jul 23 10:36 / tmp/user1dir/
[root@Redhat6 /] # find /-user root-gid 500 # find the user root,gid is 500
/ tmp/user1dir
[root@Redhat6 /] # ls-ld / tmp/user1dir/
Drwxrwxr-x 2 root 500 4096 Jul 23 10:36 / tmp/user1dir/
3) Type of file
-type
F file
D directory
B block equipment
C character device
L conform to the linked file
P command pipe file
S socket file
4) size of the file
-size
# [k | M | G]: # indicates a number, and fuzzy matching occurs when matching
+ # [k | M | G]: + # means greater than, and the matching result is greater than #
-# [k | M | G]:-# means less than, and the matching result is less than #
5) File modification time
-atime [+ | -] #: access time. Default is days. # indicates the time point of # days. + # means no access for at least # days.-# means no access within # days.
-mtime [+ | -] #: modification time. # means that the time point of # days has not been modified, + # means that it has not been modified for at least # days, and-# means that it has not been modified within # days
-ctime [+ | -] #: change time, # means that the time point of # days has not been changed, + # means that at least # days have not been changed, and-# means that it has not been changed within # days
-amin [+ | -] #: time is minutes, # means that the time point of # minutes has not been accessed, + # means that at least # minutes have not been accessed, and-# means that no access has been made within # minutes
-mmin [+ | -] #: time is minutes, # means that the time point of # minutes has not been modified, + # means that at least # minutes have not been modified, and-# means that it has not been modified within # minutes
-cmin [+ | -] #: time is minutes, # means that the time point of # minutes has not been changed, + # means that at least # minutes have not been changed, and-# means that it has not been changed within # minutes
6) File permissions
-perm [+ | -] MODE
No [+ | -] indicates exact permission matching
+ indicates that any one of the permissions of any type of user matches
-indicates that each permission of each type of user matches
Find supports the combination of search conditions when looking for standards, and the priority should be considered when using the combination of search conditions, the priority is in the order of non-→ and → or, when the combined parameters want to change the priority, you can use () to raise the priority.
-a (and) is associated with the default
-o (or) or
-Nothball! Non
The processing action of find can be:
-print defaults to output
-ls displays the details of the files found
-ok COMMAND\; confirm
-exec COMMAND\; when operating on the found file in COMMAND, use {} to replace the found file,\; means to use the Terminator of-exec, which is a fixed format; when using-exec to find the file, you can also pipe it to the xargs command to solve the problem. When xargs executes the command, if there is an operation on the file, use the-I option, and {} also indicates the file to be operated.
The code is as follows:
1. Find all the files under the / var directory that are mainly root and whose group is mail.
Find / var-user root-group mail
2. Find files in the / usr directory that do not belong to root,bin or student
Find / usr-not\ (- user root-o-user bin-o-user student\)
Find / usr-not-user root-a-not-user bin-a-not-user student
3. Find files in the / etc directory that have been modified in the last week and do not belong to root and student users
Find / etc-mtime-7-a-not-user root-a-not-user student
Find / etc-mtime-7-a-not\ (- user root-o-user student\)
4. Find the files that have no owners or groups on the current system and have been accessed in the last 1 day, and change them to root.
Find /\ (- nouser-o-nogroup\)-a-atime-1-exec chown root:root {}\
5. Find the files larger than 1m in the / etc directory and write their filenames into the / tmp/etc.largefiles file
Find / etc-size + 1m-exec echo {} > > / tmp/etc.largefiles\
Find / etc-size + 1m > > / tmp/etc.largefiles
6. Find the files in the / etc directory that all users do not have write permission to, and show their details.
Find / etc-not-perm + 222
7. The deletion type is not a directory, and there is no file for the owner
Find /-not-type d-a-nouser-exec rm-f {}\
Find /-not-type d-a-nouser | xargs-I rm-f {}
The above is all the contents of the article "how to use find commands in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.