Linux basics-file search command find, linux SEARCH Command find
I. Benefits of the find command
Sometimes it is often possible to find a specific file or directory in the directory, but it is difficult to find many files in the directory. In this case, you do not need to manually view all the files. Use the find command to help you find the files. Therefore, files or directories must be categorized and stored in an orderly manner, which makes it much easier to find. If you use the find command as few as possible during peak network hours, the query will be much slower during peak network hours.
Ii. find Command Format and Common commands
Command Format:
Find [dest_dir] [options] pattern
Parameter description:
(1) [dest_dir]: Specifies the directory. If no value is specified, it is in the current directory.
(2) [options]: for example,-name,-size, and-type. If no value is specified, search for all files or directories in the specified directory.
(3) pattern: matching mode, which can be * or?
Common commands:
Find [dest_dir]-name pattern: searches for all files or directories in the specified matching mode based on their names in the specified directory, which is case sensitive.
Find [dest_dir]-iname pattern: searches for all files or directories that match the specified pattern and ignore the case.
Find [dest_dir]-size-n: searches for all files with a file size within n in the specified directory. In Linux, data blocks are queried based on data blocks. in Linux, the size of a data block is 0.5 kb, if you want to find a 10 MB (10 MB = 10 × 1024B = 10240B = 20480 data blocks) file, run the find/temp-size-20480 command.
Find [dest_dir]-size + n: searches for all files whose file size exceeds n in the specified directory.
Find [dest_dir]-type f: searches for all files in the specified directory.
Find [dest_dir]-type d: find all directories under the specified directory.
Find [dest_dir]-type l: searches for all soft links in the specified directory.
Find [dest_dir]-amin-n: find the file or directory that has been modified for access within n minutes under the specified directory, where a is access.
Find [dest_dir]-amin + n: find the files or directories in the specified directory that have been modified for more than n minutes, where a is access.
Find [dest_dir]-cmin-n: find the file or directory under the specified directory that has been modified for n minutes, where c is change.
Find [dest_dir]-cmin + n: find the file or directory under the specified directory that has been modified for more than n minutes, where c is change.
Find [dest_dir]-mmin-n: searches for files or directories with modified content within n minutes under the specified directory, where m is modify.
Find [dest_dir]-mmin + n: find the files or directories in the specified directory that have been modified for more than n minutes, where m is modify.
Find [dest_dir]-user pattern: searches for files or directories with the specified matching mode under the specified directory.
Find [dest_dir]-group pattern: searches for files or directories with the specified matching mode in the specified directory.
Iii. effect demonstration
(1) Search for all files or directories starting with AB in the etc directory. the Linux Command is as follows. The effect is 3-1.
1 find /etc -name ab*
Figure 3-1
(2) Search for all files or directories starting with AB or AB in the etc directory. the Linux Command is as follows, and the effect is 3-2.
1 find /etc -iname AB*
Figure 3-2
(3) Search for all files with a size greater than 1 mb in the etc directory. the Linux Command is as follows, as shown in Figure 3-3.
1 find /etc -size +2048
Figure 3-3
(4) Find the files or directories modified within 2 minutes under the etc directory. the Linux Command is as follows, and the effect is shown in 3-4.
1 find /etc -mmin -2
Figure 3-4
(5) Find all soft links under the etc directory. the Linux Command is as follows, and the effect is shown in Figure 3-5.
1 find /etc -type l
Figure 3-5
(6) Find all the files or directories under the/home/centos directory whose directory belongs to jsg. the Linux Command is as follows, as shown in Figure 3-6.
1 find /home/centos -user jsg
Figure 3-6