The Find command is used primarily for file or directory lookups.
-print indicates that a matching file name is printed
-print0 indicates that each matching file name is printed using the ' \ \ ' delimiter
-name: Find by file name
-iname Ignore letter case
If you want to match one of several conditions, you can use the OR action:
-path matches the file path as a whole.
-regex: similar to path but matched based on regular expressions
! The meaning of negative parameters:
Search based on directory depth:
the Find command iterates through all subdirectories as it is used. Parameters -maxdepth and-mindepth can be used to limit the depth of traversal.
Search by File type:
Filter the file types with-type.
List all directories:-type D
List only ordinary files:-type f
List only Symbolic Links:-type l
Search by file time:
There are three timestamps in each file in the Unix/linux file system:
- Access Time (-atime): User last access time
- Modification Time (-mtime): The time the file content was last modified
- Change Time (-ctime): File metadata (metadata, such as permissions or ownership) time of last change
- represents less than,+ means greater than
FILE-size-based search:
Find files larger than 2KB :find-type f-size +2k
Units are:
B -Block( Kbytes)
C- Byte
W -word (2 bytes)
K -kilobyte
M- Megabyte
G -gigabyte
To delete a matching file:
-delete
Match based on file permissions and ownership:
-perm Permission Value
Let find skip a specific directory:
For example, in the version control system git to find a specific file when the skip . Git directory:
Find.−name". GIt"−prune -O−typef−print
which −n< Span id= "mathjax-span-38" class= "Mi" >am e " . gi t " −pr un e
to ignore a directory and the files under it, Use-prune;
−typef−print indicates the action that needs to be performed.
Shell Command Learning