Linux Security Basics: Use of the find command and use of the find command
The find command is used to find the specified file in the file system.
* Command Format: find pathname-option [-print-exex-OK]
1. pathname: directory path to be searched
~ Indicates the home Directory
. Indicates the current directory
/Indicates the root directory
2. Options
-Name: search by name
-Perm: search by File Permission
-Prune: not found in the specified directory
-Type: search by file type
-User: Find the file or directory of the specified owner
-Group: searches for files or directories in the specified group.
-Nouser: Search for files without a valid owner
-Nogroup: Find the objects in the five valid groups.
-Depth: searches for the deepest subdirectories in a specified directory.
-Size: searches for objects of the specified size.
3. Parameters
-Print: The find command outputs matching files to the standard output.
-Exec: The find command executes the shell command given by this parameter on the matching file. The corresponding command is in the form of 'command' {};. Note the space between {} And.
-OK: The Role of-exec is the same, but the shell command given by this parameter is executed in a safer mode. A prompt is displayed before each command is executed, let the user determine whether to execute.
4. Use the-name option to search by name
In the current directory and subdirectory, find the txt file starting with an upper-case letter.
Find.-name' [A-Z] *. txt '-print
In/etc and Its subdirectories, find the file starting with host
Find/etc-name 'mo * '-print
In the HOME directory and Its subdirectories, find all files
Find ~ -Name '*'-print
In the current directory and subdirectory, find txt files not starting with out
Find.-name "d *"-prune-o-name "*. txt"-print
5. Search by directory
Search for txt files in subdirectories other than aa in the current directory
Find.-path "./abc"-prune-o-name "*. txt"-print
Search for txt files in the current directory and subdirectories other than aa and bb
Find. \ (-path "./aa"-o-path "./bb" \)-prune-o-name "*. txt"-print
Find the txt file in the current directory and no longer in the subdirectory
Find .! -Name "."-type d-prune-o-type f-name "*. txt"-print
6. Search by File Permission
In the current directory and subdirectory, find the owner with read/write execution and other files with read execution permissions.
Find.-perm 755-print
7. Search by file type
Find the symbolic link file in the current directory and subdirectory
Find.-type l-print
Find all symbolic link files in the/etc directory. You can use
$ Find/etc-type l-print
8. Search for files by owner and group
Search for objects whose owner is tt
Find/-user tt-type f-print
Search for files deleted by the owner
Find/-nouser-type f-print
Search for admin files in the group
Find/-group admin-type f-print
Search for files deleted from a user group
Find/-nogroup-type f-print
9. Search by size
Search for files larger than 1 MB
$ Find/-size + 1 M-type f-print
Search for files equal to 6 bytes
$ Find.-size 6c-print
Search for files smaller than 32 KB
$ Find.-size-32 k-print