How Linux searches for files

  
 

#whereis Finding installed software

Finding a file on Linux is a cumbersome task. After all, in Linux we need to use the dedicated "find" command to find files on the hard disk. The file expression format under Linux is very complicated. Unlike WINDOWS, DOS is a unified AAAAAAA.BBB format. It is convenient to find. In WINDOWS, it is very easy to find the file name or suffix of the file to be found. The command to find files in Linux is usually the "find" command, and the "find" command can help us find the files we need in the daily affairs of using and managing Linux. For Linux novices, the "find" command is also a way to understand and learn the characteristics of Linux files. Because Linux has a large number of distributions, the version is upgraded very quickly. In Linux books, the location of a configuration file is often written. Often Linux novices can't find it according to the figure. For example, the hard disk location and file directory of some important configuration files in REDHAT Linux 7.O and REDHAT Linux 7.1 have changed a lot. If you don't learn to use the "find" command, then there are thousands of Linux. It's quite difficult to find one of the files in the file. I have had this kind of suffering before I mastered the “find” order. Ok, here's a detailed introduction to the powerful use of the "find" command.

Search by file name:

This method is as easy to understand as finding files under WINDOWS. If you put this file in a single folder, you can easily find it by using the common “ls" command. If you use the “find” command to find it, you can't leave a deep impression on it. After all, “find” The power of the command is more than this. If you know the file name of a file, you don't know which folder the file is placed in, or even a layered folder. For example, suppose you forgot which directory of the system httpd.conf is in the system, or even somewhere in the system, you can use the following command:

#find /-name httpd .conf

This command syntax seems to be easy to understand, just write -name directly after the find, indicating that the system is required to find the file name, and finally write the target file name httpd.conf. Wait a moment, the system will display a list of search results on the computer screen:

etc/httpd/conf/httpd.conf

This is the complete httpd.conf file in the Linux system. path. The search was successful.

If the system does not show the result after entering the above search command, then do not think that the system does not execute the find/-name httpd.conf command, but the Apache server may not be installed on your system. The Apache web server is installed, and then the configuration file can be found using find /-name httpd.conf.

No error finding tips:

In Linux systems, the "find" command is a command that most system users can use and is not a patent of the ROOT system administrator. However, it is also possible for ordinary users to use the “find” command to encounter the problem that the system administrator ROOT in the Linux system can set certain file directories to the access-free mode. In this way, ordinary users do not have permission to query these directories or files with the “find” command. When a normal user uses the “find” command to query these file directories, the words "Permissiondenied." are often displayed. The system will not be able to find the file you want. In order to avoid such errors, we try to find the file by using the method of transferring error prompts. Enter find /-name access_log 2>/dev/null

This method is to transfer the search error prompt to a specific directory. go with. After the system executes this command, the error message is sent directly to stderrstream 2, access_log 2 means that the system will send the error message to stderrstream 2, /dev/null is a special file indicating empty or wrong Information, so the error message queried will be transferred and will not be displayed again.

Finding files on Linux systems also encounters such a practical problem. If we look at a file on the entire hard drive, it takes a long time to find a file, especially for large Linux systems and larger hard drives, where files are placed in deeply nested directories. If we know that this file is stored in a large directory, then it can save a lot of time by looking down in this directory. This can be solved by using find /etc -name httpd.conf. The above command means to query the httpd.conf file in the etc directory. Here again, the meaning of this function symbol, if you enter "find /& rdquo" means that the Linux system is required to find files in the entire ROOT directory, that is, to find files on the entire hard disk, and "find /Etc” is to find files only in the etc directory. Because “find/etc” means that the file is only found in the etc directory, so the speed of the search is much faster.

Find method based on partial file name:

This method is the same as finding a known file name method in WINDOWS. However, the way to find files based on partial file names in Linux is much more powerful than the similar lookup methods in WINDOWS. For example, if we know that a file contains the three letters srm, then it is achievable to find all the files containing the three letters in the system. Enter:

find /etc -name '*srm* '

This command indicates that the Linux system will look for all three-letter files containing srm in the entire /etc directory, such as absrmyz, tibc.srm, etc. If you also know that this file is started by the three letters srm, then we can also omit the first asterisk, the command is as follows:

Copyright © Windows knowledge All Rights Reserved