Each operating system is made up of thousands of different kinds of files . Among them are the files of the system itself , User's own files , And shared files and so on . Sometimes we often forget where a file is on the hard disk . In Microsoft WINDOWS It's quite easy to find a file in an operating system , Just click on the desktop “ Start ”－“ Search for ” Can be on the local hard disk in various ways , local area network , Even in INTERNET Look up all kinds of files on the Internet , file . But the use of Linux Our users are not so lucky , stay Linux It's really a troublesome thing to find a file on the Internet . After all, Linux We need to use special “ lookup ” Command to find files on the hard disk .Linux The file format under is very complex , Don't like WINDOWS,DOS It's all unified AAAAAAA.BBB Format is so easy to find , stay WINDOWS in , As long as you know the file name or suffix of the file you want to find, it's very easy to find .Linux The command to find a file in is usually “find” command ,“find” Command can help us use , management Linux In our daily affairs, we can easily find out the documents we need . about Linux beginners ,“find” Command is also understanding and learning Linux Method of document characteristics . because Linux There are many releases , Version upgrade is fast , stay Linux Books often indicate the location of a configuration file , Often Linux The novice still can't find . for instance REDHAT Linux 7.O and REDHAT Linux 7.1 Some important configuration files in the hard disk location and file directory have changed a lot , If you don't learn how to use “find” command , So in thousands of Linux It's quite difficult to find one of the configuration files in the file , I am not proficient in “find” I've suffered from this before the order . good , Here is a detailed introduction to the powerful “find” All methods and uses of the command . Search by filename ： This method is similar to WINDOWS It's just as easy to understand . If you put this file in a single folder , Just use the common “ls" The command can be easily found out , So use “find” You can't be impressed by the command to find it , After all “find” The power of command is more than this . If you know the filename of a file , I don't know which folder this file is in , Even in folders that are nested layer by layer . Illustrate with examples , Suppose you forget httpd.conf Which directory is this file in , Even in some part of the system , Then you can use the following command ： find / -name httpd.conf This command syntax seems easy to understand , It's directly in find Write... On the back -name, Indicates that the system is required to search by filename , Finally, write httpd.conf The target filename is just . After a while, the system will display a list of search results on the computer screen ： etc/httpd/conf/httpd.conf This is it. httpd.conf This file is in Linux The full path in the system . Find success . If the system does not display the result after inputting the above search command , So don't think the system didn't execute find/ -name httpd.conf command , And maybe it's not installed in your system Apache The server , At this time as long as you install Apache Web The server , And then use find / -name httpd.conf You can find the configuration file . Error free search techniques ： stay Linux In the system “find” Commands are commands that most system users can use , Not at all ROOT System administrator's patent . But ordinary users use “find” There is also the possibility of such a problem when ordering , That's it Linux System administrator in the system ROOT Some file directories can be set to no access mode . In this way, ordinary users have no permission to use “find” Command to query these directories or files . When ordinary users use “find” The command to query these file directories is , There are often "Permissiondenied."（ Blocking access ） word . The system will not be able to find the file you want . To avoid such a mistake , We try to find the file by transferring the error prompt , Input find / -name access_log 2>/dev/null This method is to transfer the error prompt to a specific directory . After the system executes this command , In case of any error, the information will be sent directly to stderrstream 2 in ,access_log 2 It means that the system will send error messages to stderrstream 2 in ,/dev/null It's a special document , Indicate empty or incorrect information , In this way, the error information will be transferred , It won't show .
stay Linux The system will also encounter such a practical problem when looking for files . If we're on the entire hard drive , It takes a long time to find a file in this system , Especially the large-scale Linux System and large capacity hard disk , When the file is in a nested Directory . If we know that this file is stored in a large directory , So just looking down in this directory can save a lot of time . Use find /etc -name httpd.conf And then we can solve this problem . The above command is expressed in etc Search in the directory httpd.conf This file . Here's another explanation “/ ” The meaning of this function symbol , If input “find/ ” It means to ask for Linux The system is in the whole ROOT Find files in the directory , That is to find files on the whole hard disk , and “find/etc” It's just etc Find files in the directory . because “find/etc” Only in etc Find files in the directory , So the speed of searching is much faster . Search method according to some file names ： This method and in WINDOWS The way to find a known filename is the same . But in the Linux The method of finding a file based on part of the file name in is better than in WINDOWS The same search method in is much more powerful . For example, we know that a file contains srm this 3 Letters , Then find all the systems that contain this 3 A letter file can be implemented , Input ： find /etc -name 'srm' This order shows Linux The system will be in /etc Find all the contents in the whole directory srm this 3 A letter file , such as absrmyz, tibc.srm All the documents that meet the requirements can be displayed . If you also know that this document was created by srm this 3 A letter begins with , Then we can omit the first asterisk , The order is as follows ： find/etc -name 'srm*' It's just like srmyz This kind of file was found out , like absrmyz perhaps absrm Such documents do not meet the requirements , Not shown , In this way, the efficiency and reliability of finding files are greatly enhanced . According to the characteristics of the file query method ： If you only know the size of a file , Features such as modification date can also be used “find” Command to find out , This sum WINDOWS In the system " Search for " The function is basically the same . In Microsoft " Search for " in WINDOWS Medium " Search Assistant " Make search for files and folders 、 The printer 、 It's easier for users and other computers on the network . It even makes in Internet It's easier to search ." Search Assistant " It also includes an indexing service , This service maintains the index of all files in the computer , Make search faster . Use " Search Assistant " when , Users can specify multiple search criteria . for example , The user can press the name 、 Type and size search for files and folders . Users can even search for files that contain specific text . If the user is using Active Directory, You can also search for printers with a specific name or location . For example, we know a Linux File size is 1,500 bytes, Then we can use the following command to query find / -size 1500c, character c Indicates that the size of the file to be searched is based on bytes In units of . If we don't know the exact size of this file , So in Linux The fuzzy search method can also be used to solve . For example, we input find/ -size +10000000c This command , It indicates that the system specified by us finds the value greater than in the root directory 10000000 Byte file and display it . In the command “＋” It means that the system is required to list only files larger than the specified size , While using “-” The system is required to list files smaller than the specified size . The following list is in Linux Use different “ find" The search action that the system will make after the command , It's easy to see from it that Linux Use in “find" There are many ways to command ,“ find" Command search files as long as flexible application , It doesn't have to be WINDOWS Poor search ability in . find / -amin -10 # Find last in system 10 Files accessed in minutes find / -atime -2 # Find last in system 48 Files accessed in hours find / -empty # Find files or folders that are empty in the system find / -group cat # Find in system belongs to groupcat The file of find / -mmin -5 # Find last in system 5 Files modified in minutes find / -mtime -1 # Find last in system 24 Documents modified in hours find / -nouser # Search for invalid user files in the system find / -user fred # Find in system belongs to FRED This user's file The following list is right find Command to specify the characteristics of the file to find some of the conditions . Not all the search criteria are listed here , Refer to about Linux You can know all about books find Command search function . -amin n Find the last in the system N Files accessed in minutes -atime n Find the last in the system n24 Files accessed in hours -cmin n Find the last in the system N Minutes of changed state files -ctime n Find the last in the system n24 Hours of changed state files -empty Look for blank files in the system , Or a blank file directory , Or a folder with no subdirectories in the directory -false Find files that are always wrong in the system -fstype type Find files in the system that exist in the specified file system , for example ：ext2 . -gid n Find file digital groups in the system ID by n The file of -group gname Find the files in the system belong to gnam Filegroups , And specify groups and ID The file of Find Command control options description ： Find The command also provides the user with some unique options to control the search operation . The following table is the most basic summary , Most commonly used find Command control options and their usage . Options Use description -daystart . Test the system from today 24 Documents within hours , Usage is similar. -amin -depth Use depth level search process , Search the file content in the specified directory of a certain layer first -follow Follow the wildcard link to find ; in addition , You can also ignore the wildcard link mode query -help Show command summary -maxdepth levels Look up... In a hierarchical directory in a decreasing way -mount Don't look in the file system directory , Usage is similar. -xdev. -noleaf Forbidden in Africa UNUX file system ,MS-DOS System ,CD-ROM Optimized search in file system -version Print version numbers Use -follow After the options ,find The command follows the wildcard link to find , Unless you specify this option , Otherwise, in general find The command will ignore the wildcard link mode for file search . -maxdepth The function of options is to limit find The command searches for files in the directory in a descending way when the file is over a certain level or too many directories , This causes the search to slow down , Too much time spent searching . for example , We need to be in the present (.) Look up a directory named fred The file of , We can use the following command find . -maxdepth 2 -name fred If the fred The file in ./sub1/fred Directory , So this command will directly locate this file , The search is easy to succeed . If , This file is in ./sub1/sub2/fred Directory , Then this command can't find . Because I've already given find The maximum query directory level of the command in the directory is 2, You can only find 2 Files in the layer Directory . The purpose of this is to make find Command to locate files more precisely , If you already know the approximate number of directories in which a file is located , Then join in -maxdepth n It can be found in the specified directory quickly . Use hybrid search to find files find The command can use the hybrid search method , For example, we want to be in /tmp Look in the directory for more than 100000000 Bytes and 48 A file modified within hours , We can use -and To combine two search options into a hybrid search . find /tmp -size +10000000c -and -mtime +2 All friends who have studied computer language know , In computer language , Use and ,or respectively “ And ” and “ or ” The relationship between . stay Linux The system's search commands are just as common . There are also examples of this , find / -user fred -or -user george We can explain it in /tmp Look up in the directory that belongs to fred perhaps george The files of these two users . stay find You can also use “ Not ” The relationship to find the file , If we want to /tmp Look in the directory for anything that doesn't belong to panda The file of , Use a simple find /tmp ! -user panda The order can solve . It's simple . How to find and display files Finding a file is our goal , We would like to know more about the details and properties of the found file , If we take a look at the file now , In the use of LS Command to view file information is quite cumbersome , Now we can also combine these two commands . find / -name "httpd.conf" -ls The system found httpd.conf Immediately after the file is displayed on the screen httpd.conf file information . 12063 34 -rw-r--r-- 1 root root 33545 Dec 30 15:36 /etc/httpd/conf/httpd.conf The following table is some commonly used parameters and usage for finding files and displaying file information Options Use description -exec command; Find and execute commands -fprint file Print file full file name -fprint0 file Print file full file name including empty file -fprintf file format Print file format -ok command; Give the user the command to perform the operation , According to the user's Y Confirm input execution -printf format Print file format -ls Print documents in the same format . summary ： So far we have learned more about find How to use commands , It also lists many commonly used find Command options , If we can master it skillfully in Linux in find How to use commands , So in Linux It's not hard to find files in .
That's all Liangxu tutorial website For all of you Linux Related knowledge .