A linux command (22) every day: detailed description of the parameters of the find command link: A linux command every day (1): ls command http://www.2cto.com/os/201210/163049.html ; One linux command every day (2): cd command http://www.2cto.com/os/201210/163050.html ; Every day... a linux command (22) every day: detailed description of the parameters of the find command link: A linux command every day (1): ls command http://www.2cto.com/os/201210/163049.html ; One linux command every day (2): cd command http://www.2cto.com/os/201210/163050.html ; One linux command every day (3): pwd command http://www.2cto.com/os/201210/163462.html ; One linux command every day (4): mkdir command http://www.2cto.com/os/201210/163463.html ; One linux command every day (5): rm command http://www.2cto.com/os/201210/163662.html ; One linux command (6) every day: rmdir command http://www.2cto.com/os/201210/164017.html ; One linux command (7) every day: mv command http://www.2cto.com/os/201210/164247.html ; One linux command every day (8): cp command http://www.2cto.com/os/201210/164254.html ; One linux command every day (9): touch Command http://www.2cto.com/os/201211/165699.html ; One linux command every day (10): cat command http://www.2cto.com/os/201211/165989.html ; One linux command every day (11): nl command http://www.2cto.com/os/201211/165990.html One linux command every day (12): more command http://www.2cto.com/os/201211/165994.html One linux command every day (13): less command http://www.2cto.com/os/201211/165998.html One linux command every day (14): head Command http://www.2cto.com/os/201211/166191.html One linux command every day (15): tail command http://www.2cto.com/os/201211/168702.html One linux command every day (16): which command http://www.2cto.com/os/201211/168890.html A linux command (17) every day: whereis command http://www.2cto.com/os/201211/168893.html One linux command (18) every day: locate command http://www.2cto.com/os/201211/168895.html One linux command every day (19): find command overview http://www.2cto.com/os/201211/168897.html One linux command every day (20): find command exec http://www.2cto.com/os/201211/168901.html One linux command (21) every day: find command xargs http://www.2cto.com/os/201211/168903.html Find some common examples of some common parameters and some specific usage and precautions. 1. use the name option: www.2cto.com file name option is the most common option for the find command. either use this option independently or use it with other options. You can use a certain file name pattern to match the file. remember to use quotation marks to cause the file name pattern. No matter what the current path is, if you want to find a file with a file name *. log in your root directory $ HOME, use ~ As the 'pathname' parameter, the tilde ~ Represents your $ HOME directory. Find ~ -Name "*. log "-print: Search for all '* in the current directory and subdirectory '*. log' file. you can use: find. -name "*. log "-print to search for files whose names start with an uppercase letter in the current directory and subdirectory. you can use: find. -name "[A-Z] *"-print: find/etc-name "host *"-print to find the files in the $ HOME directory, you can use: find ~ -Name "*"-print or find.-print: to enable the system to run at high load, search for all files from the root directory. Find/-name "*"-print if you want to find the file names in the current directory starting with lowercase letters, then add 4 to 9. log File: Command: find. -name "[a-z] * [4-9]. log "-print output: [root @ localhost test] # ll total bytes -rw-r -- r -- 1 root 302108 11-13 03 log2012.log-rw-r -- 1 root 61 11-13 03 log2013.log-rw -r -- 1 root 0 11-13 log2014.log-rw-r -- 1 root 0 11-13 06: 06 log2015.logdrwxr-xr-x 6 root 4096 10- 27 0:58 scfdrwxrwxr-x 2 root Root 4096 11-13 test3drwxrwxr-x 2 root 4096 11-13 test4 [root @ localhost test] # find. -name "[a-z] * [4-9]. log "-print. /log2014.log. /log2015.log. /test4/log2014.log [root @ localhost test] #2. perm option: use the-perm option in file permission mode, and search for files in file permission mode. It is best to use the octal permission notation. For example, in the current directory, find a file with a permission of 755, that is, the file owner can read, write, and execute the file. other users can read and execute the file. you can use: [root @ localhost test] # find. -perm 755-print .. /scf. /scf/lib. /scf/service. /scf/service/deploy. /scf/service/deploy/product. /scf/service/deploy/info. /scf/doc. /scf/bin [root @ localhost test] # Another expression: add a horizontal bar before the octal number to indicate that all matches. for example,-007 is equivalent to 777, -005 is equivalent to 555. Command: find. -perm-005 output: [root @ localhost test] # ll total bytes -rw-r -- r -- 1 root 302108 11-13 03 log201 2. log-rw-r -- 1 root 61 11-13 06:03 log2013.log-rw-r -- 1 root 0 11-13 06:03 log2014.log-rw-r -- 1 root 0 11-13 log2015.logdrwxr-xr-x 6 root 4096 10-27 scfdrwxrwxr-x 2 root 4096 11-13 test3drwxrwxr-x 2 root 4096 11-13 05:50 test4 [root @ localhost test] # find. -perm-005 .. /test4./scf. /scf/lib. /scf/service. /scf/service/deploy. /scf/service/deploy/p Roduct. /scf/service/deploy/info. /scf/doc. /scf/bin. /test3 [root @ localhost test] #3. ignore a directory: If you want to ignore a directory when searching for a file because you know that there is no file in the directory, you can use the-prune option to specify the directory to be ignored. Be careful when using the-prune option, because if you use the-depth option at the same time, The-prune option will be ignored by the find command. To search for files in the test Directory but not in the test/test3 Directory, run the following command: find test-path "test/test3"-prune-o-print output: [root @ localhost soft] # find test-path "test/test3"-prune-o-printtesttest/log2014.logtest/log2015.logtest/test4test/test4/log2014.logtest/test4/log2013.logtest/test4/log2012.log /scftest/scf/libtest/scf/servicetest/scf/service/deploytest/scf/service/deploy/producttest/scf/service/deploy/infotest/scf/ Doctest/scf/bintest/log2013.logtest/log2012.log [root @ localhost soft] #4. how to avoid a file directory when searching for files using find: instance 1: find all files not in the test4 subdirectory in the test Directory: find test-path "test/test4"-prune-o-print output: [root @ localhost soft] # find testtesttest/log2014.logtest/log2015.logtest/test4test/test4/log2014.logtest/test4/tests/test4/log2012.logtest/scftest/scf/libtest/scf/servicetest/scf/ service/deploytest/scf/service/d Eploy/producttest/scf/service/deploy/infotest/scf/doctest/scf/bintest/log2013.logtest/log2012.logtest/test3 [root @ localhost soft] # find test-path "test/test4 "-prune-o-printtesttest/log2014.logtest/log2015.logtest/scftest/scf/libtest/scf/servicetest/scf/service/deploytest/scf/service/deploy/producttest/scf/service/ deploy/infotest/scf/doctest/scf/bintest/log2013.logtest/log2012.logtest/test3 [root @ Localhost soft] # Description: find [-path ..] [expression] The short expression behind the path list is-path "test"-prune-o-print is-path "test"-a-prune-o-print. Press order evaluation, -both a and-o are short-circuit values. they are similar to shell's & | if-path "test" is true,-prune and-prune return true values, true for the logical expression; otherwise, the value-prune is not required, and the logical expression is false. If-path "test"-a-prune is false, evaluate-print,-print to return true, or the logical expression is true; otherwise, the value-print is not required, or the logical expression is true. The special expression combination can be written as: if-path "test" then-prune else-print instance 2: Avoid multiple folders: command: find test \ (-path test/test4-o-path test/test3 \)-prune-o-print output: [root @ localhost soft] # find test \ (-path test/test4-o-path test/test3 \) -prune-o-printtesttest/log2014.logtest/log2015.logtest/scftest/scf/libtest/scf/servicetest/scf/service/deploytest/scf/service/deploy/producttest/scf/service/deploy /infotest/scf/ Doctest/scf/bintest/log2013.logtest/log2012.log [root @ localhost soft] # Note: parentheses indicate the combination of expressions. \ Indicates a reference, that is, it indicates that shell does not give a special explanation for the subsequent characters, but leaves it to the find command to explain its meaning. Instance 3: find a specific file, add-name and other options after-o command: find test \ (-path test/test4-o-path test/test3 \) -prune-o-name "*. log "-print output: [root @ localhost soft] # find test \ (-path test/test4-o-path test/test3 \)-prune-o-name "*. log "-printtest/log2014.logtest/log2015.logtest/log2013.logtest/log2012.log [root @ localhost soft] #5. use the user and nouser options: search for files by file owner: instance 1: find the file whose owner is peida in the $ HOME directory command: find ~ -User peida-print instance 2: find the file whose owner is peida in the/etc directory: Command: find/etc-user peida-print description: instance 3: you can use the-nouser option to find files that have been deleted by the owner account. Find all such files in the/home directory. Command: find/home-nouser-print description: in this way, you can find the files whose owner does not have a valid account in the/etc/passwd file. When you use the-nouser option, you do not need to give a user name. The find command can complete the corresponding work for you. 6. use the group and nogroup options: like the user and nouser options, the find Command also has the same options for the user group to which the file belongs, to find files belonging to the gem user group in the/apps directory, you can use: find/apps-group gem-print to find all files that do not have a valid user group. you can use the nogroup option. The following find command looks for such a file from the root directory of the file system: find/-nogroup-print7. search for files by change time or access time: if you want to search for files by change time, you can use the mtime, atime, or ctime options. If the system suddenly has no available space, it is very likely that the length of a file will increase rapidly during this period, then you can use the mtime option to find such a file. Use minus signs-to limit the files whose change time is earlier than n days ago, and use the plus sign + to limit the files whose change time is earlier than n days ago. To search for files whose modification time is less than 5 days in the root directory of the system, you can use: find/-mtime-5-print to search for files whose change time is earlier than 3 days in the/var/adm directory, you can use: find/var/adm-mtime + 3-print8. search for new or old files than a file: If you want to find all files whose change time is newer than a file but older than another file, you can use the-newer option. The general format is: newest_file_name! Oldest_file_name where ,! Is a logical non-sign. Instance 1: find the file command that is newer than the file log2012.log but earlier than the file log2017.log: find-newer log2012.log! -Newer log2017.log output: [root @ localhost test] # ll total bytes -rw-r -- r -- 1 root 302108 11-13 03 log2012.log-rw-r -- 1 root 61 11-13 03 log2013.log-rw -r -- 1 root 0 11-13 log2014.log-rw-r -- 1 root 0 11-13 06: 06 log2015.log-rw-r -- 1 root 0 11-16 log2016.log-rw-r -- 1 root 0 11-16 log2017.logdrwxr-xr-x 6 root 4096 10-27 0scfdrwxrwxr-x 2 root 4096 11-13 test3drwxrwxr-x 2 root 4096 11-13 test4 [root @ localhost test] # find-newer log2012.log! -Newer log2017.log .. /log2015.log. /log2017.log. /log2016.log. /test3 [root @ localhost test] # instance 2: find the new file command: find. -newer log2012.log-print output: [root @ localhost test] # find-newer log2012.log .. /log2015.log. /log2017.log. /log2016.log. /test3 [root @ localhost test] #9. use the type option: instance 1: find all Directory commands in the/etc directory: find/etc-type d-print instance 2: find all types of files except directories in the current directory. Command: find .! -Type d-print instance 3: find all symbolic link files in the/etc directory command: find/etc-type l-print10. use the size option: you can search for a file based on the file length. the file length referred to here can be measured by block or byte. The length of a byte metering file is N c. The length of a block metering file is represented by only numbers. When searching for a file based on the file length, this file length in bytes is generally used. you can view the file system size because block metering is easier to convert. Instance 1: find a file with a length greater than 1 MB in the current directory. Command: find. -size + 000000c-print instance 2: find a file with a length of exactly 100 bytes in the/home/apache Directory: command: find/home/apache-size 100c-print instance 3: search for files with more than 10 blocks in the current directory (one is 512 bytes) command: find. -size + 10-print11. use the depth option: when using the find command, you may want to match all files first and then search for them in the subdirectory. Use the depth option to run the find command. One reason for this is that when you use the find command to back up the file system on the tape, you want to back up all the files first, and then back up the files in the subdirectories. Instance 1: The find command starts from the root directory of the FILE system and looks for a FILE named CON. FILE. Command: find/-name "CON. FILE "-depth-print description: it will first match all files and then go to the subdirectory to find 12. use the mount option: find files in the current file system (do not enter other file systems), you can use the mount option of the find command. Example 1: run the find.-name "*. XC"-mount-print command to find the file whose name ends with XC in the current directory.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.