Find is a powerful file search tool under Linux
Before you talk about this tool, you'll find another Linux search tool.
Locate: Database dependent (manual generation of database UpdateDB, time consuming)
Non-real-time lookup, (because it is dependent on the database, the data update has a certain interval of time, can also be updated manually)
Fast Search Speed
Fuzzy Lookup
Find: Real-time lookup, slow, exact match
Find uses formatting
Find [option] [Find path] [find condition] [processing action]
[Find path]: Can be omitted, default to the current working directory [find criteria]: The defaults can be omitted, the default is to find all files under the path [Processing action]: The default is to display to the screen
Note: The directory you are looking for is best to bring up/end
Search criteria:
-name Search by file name
-iname case-insensitive with file name lookup
-user Search by Owner
-group Search by genus Group
-uid to file UID lookup
-gid Search by the GID of the file
-nouser Find files that do not belong to any user
-nogroup finding files that do not belong to any of the genus groups
-prem [+|-] MODE to search by file permissions
MODE: Exact match +mode: any one of a class of users with a permission match; often used to find out whether a particular permission exists for a certain type of user
+644 requires three bits to match, as 444,644 will match to
-mode: Each class of user specified to check the permission bits are matched;
-222 only need to have write permission on any bit on a file to match such as 200,220
-atime,-mtime,-ctime , [+|-] # Find by timestamp, in days
+ #: Indicates time outside #+1 days-#: Indicates the time within the # days #: Indicates the time of day
-amin,mmin,cmin [+|-] # in minutes
-type Find by File class
F File D directory s socket p named pipe L link file C character device B block device
-size [+|-] k, M, G
+ #M: Files larger than #m-#M: Files smaller than #m, if 1m,0.01 to 1M and below 1M will match to # M: If it is a 2m,1-2m count match
Combination conditions:
-A: with, while satisfying
- o: Or,
-not, !: Non, take counter
-a priority is greater than-o; Sometimes you need to use parentheses to escape the notation: \ (\)
Handling actions:
-exec COMMAND {} \; Performs a command operation on the found file. There are spaces after {}
-ok COMMAND {} \; Interactive-exec
-ls listed in long format, find the file
-print Display, default for this action
| Xargs COMMAND to Pipeline processing
Find and Xargs
If the find command uses the pipeline directly, find passes all matching files along to exec execution. However, some systems have a limit on the length of the command that can be passed to exec so that an overflow error occurs after the Find command runs for a few minutes. The error message is usually "parameter column too Long" or "parameter column overflow".
Then we need to use the Xargs command.
The find command passes the matched file to the Xargs command, and the Xargs command takes only a subset of the files at a time instead of all, unlike the-exec option. This allows it to first process a portion of the file that was first fetched, then the next batch, and so on.
In some systems, the use of the-EXEC option initiates a corresponding process for processing each matching file, not all of the matching files are executed once as parameters, so that in some cases there will be too many processes and degraded system performance, so the efficiency is not high;
With the Xargs command, there is only one process. In addition, when using the Xargs command, whether to get all the parameters at once or to get the parameters in batches, and the number of parameters to get each time will be determined according to the command's options and the corresponding tunable parameters in the system kernel.
Example:
1, find/var/directory is the owner of the root and belong to the group mail all files;
# find/var/-user root-a-group Mail #-A default can not write
2. Find files that are not root, bin, or Hadoop in the/usr directory;
# find/usr/-not-user root-not-user bin-not-user Hadoop
3, find the/etc/directory in the last week of its content has been modified, and does not belong to the root or Hadoop files;
4, find the current system does not belong to the main or belong to the group, and the last 1 months have been visited documents;
5, look for the/etc/directory of more than 1M and the type of ordinary files of all files;
6, find/etc/directory All users do not have permission to write files;
# find/etc/-not-perm +222
None of them: on the contrary: any one has
All have: the opposite: At least one has no
7, find the/etc/directory at least one class of users do not have write permission;
8, find/etc/init.d/directory, all users have execute permission and other users have write permission files;
This article is from "Rookie Diary" blog, please make sure to keep this source http://zkxfoo.blog.51cto.com/1605971/1662313
Find Command Xiang Solution