The Linux Find command searches the directory structure for files and performs the specified actions. The Linux Find command provides quite a lot of search criteria and is powerful. Because find has powerful features, it has a lot of options, most of which are worth taking the time to look at. Even if the system contains a network file system (NFS), the Find command works equally well in the file system, and you only have the appropriate permissions. When running a very resource-intensive find command, many people tend to put it in the background because it can take a long time to traverse a large file system (this refers to a file system with more than 30G bytes).
1. Command format:
Find Pathname-options [-print-exec-ok ...]
2. Command function:
Used to locate files in the file tree and to make corresponding processing
3. Command parameters:
The directory path that the Pathname:find command looks for. For example, use. To represent the current directory, and/to represent the system root directory.
The-print:find command outputs the matched file to standard output.
The-exec:find command executes the shell command given by the parameter to the matching file. The corresponding command is in the form of ' command ' {} \;, note the space between {} and \;
-ok: The same as-exec, except that the shell command given by the parameter is executed in a more secure mode, prompting the user to determine whether to execute before executing each command.
4. Command options:
-name finds files by file name.
-perm to find files according to file permissions.
-prune Use this option to have the Find command not be found in the currently specified directory, and if you use the-depth option at the same time,-prune will be ignored by the Find command.
-user Search for files according to the owner of the file.
-group finds files according to the group to which the files belong.
-mtime-n +n The file changes time to find the file,-n means that the file change time is now less than n days, + n means that the file change time is now N days ago. The Find command also has the-atime and-ctime options, but they both and the-m time option.
-nogroup finds a file that does not have a valid owning group, that is, the group to which the file belongs does not exist in/etc/groups.
-nouser finds a file without a valid owner, that is, the owner of the file does not exist in the/etc/passwd.
-newer file1! File2 look for a file that changes time than the file File1 new but older than the file file2.
-type find a file of a certain type, such as:
B-block device files.
D-Directory.
C-character device file.
P-Pipeline file.
L-Symbolic link file.
F-Normal file.
-size N:[c] finds files with a file length of n blocks, with C indicating the length of the file in bytes. -depth: When looking for a file, first find the file in the current directory, and then look in its subdirectories.
-fstype: Find files located in a file system of a certain type, these file system types can usually be found in the configuration file/etc/fstab, which contains information about the file system in this system.
-mount: Does not cross the file system mount point when locating files.
-follow: If the find command encounters a symbolic link file, it tracks to the file that the link points to.
-cpio: Use the cpio command for matching files to back up these files to the tape device.
In addition, the following three differences:
-amin N Find the last n minutes of files accessed in the system
-atime N Find the last n*24 hour Access file in the system
-cmin n Find files in the last n minutes of the system changed file status
-ctime n Find files that have changed file status in the last n*24 hours of the system
-mmin n Find files that have changed file data in the last N minutes of the system
-mtime n Find files that have changed file data for the last n*24 hours in the system
5. Usage examples:
Example 1: Finding files that have been modified within a specified time
command: find-atime-2 (for files modified within 48 hours)
Find -atime-2. /logs/Monitor. /. BASHRC. /. Bash_profile. /.bash_history
Example 2: Search by keyword
command:find. -name "*.log" (finds files ending with. Log in the current directory.) ". " Represents the current directory)
Find " *.log " . /Log_link.log. /Log2014.log. /test4/log3-2. Log. /test4/log3-3. Log. /test4/log3-1. Log
Example 3: Find files by directory or file permissions
command:find/opt/soft/test/-perm 777 (Find file with permission 777 in/opt/soft/test/directory)
Find 777/opt/soft/test/log_link.log/opt/soft/test/test4/opt/soft/test/test5/test3 /opt/soft/test/test3
Example 4: Find by Type
command:find. -type f-name "*.log" (Find normal files when directories end with. log)
Find " *.log " . /Log2014.log. /test4/log3-2. Log. /test4/log3-3. Log. /test4/log3-1. Log
Example 5: Find files by size
command:find. -size +1000c-print (find files larger than 1K in the current directory)
[Email protected] test]# find -size +1000c-print : /test4. /SCF. /scf/lib. /scf/service. /scf/service/Deploy. /scf/service/deploy/product
[Email protected] test]# find-size +1000c > list.txt;tar-t list.txt-zcvf size1000.tar.gz;rm-rf list.txt;
The above command says the list of files found is packaged into size1000.tar.gz with the tar command
Linux Find command