How to use the Linux find command

linux find file command find

  Every operating system is made up of thousands of different kinds of files. Among them are the files that come with the system itself, the user's own files, and shared files, and so on. We sometimes often forget where a file is on our hard drive. It is quite simple to find a file in Microsoft's WINDOWS operating system, as long as you click "Start" - "Search" on the desktop, you can find it on the local hard disk, local area network, or even on the Internet in various ways. Various documents, documents.

  However, users who use Linux are not so lucky. It is indeed a troublesome thing to find a file on Linux. After all, in Linux we need to use a dedicated "find" command to find files on the hard disk. The file expression format under Linux is very complex, unlike the unified AAAAAAA.BBB format under WINDOWS and DOS, which is easy to find. In WINDOWS, as long as you know the file name or suffix of the file you want to find, it is very easy to find. The command to find files in Linux is usually the "find" command. The "find" command can help us easily find the files we need in the daily affairs of using and managing Linux. For Linux newbies, the "find" command is also a way to understand and learn the characteristics of Linux files. Because there are many Linux distributions and versions are upgraded quickly, the location of a certain configuration file is often written in Linux books. For example, in REDHAT Linux 7.0 and REDHAT Linux 7.1, the hard disk locations and file directories where some important configuration files are located have changed a lot. If you don't learn to use the "find" command, then thousands of Linux file It is quite difficult to find one of the configuration files in . Well, the following is a detailed introduction to all the methods and uses of the powerful "find" command.

  Find by filename:

  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 with the common "ls" command, then using the "find" command to find it will not impress you, after all "find" "The power of the command doesn't stop there. If you know the file name of a file, you don't know which folder the file is placed in, or even a nested folder. For example, if you forget which directory the httpd.conf file is in on the system, or even somewhere on the system, you can use the following command:

  find / -name httpd.conf

  This command syntax looks like It is easy to understand, that is, write -name directly after find, indicating that the system is required to search according to the file name, and finally write the target file name of httpd.conf. After a while, the system will display a list of search results on the computer screen:
etc/httpd/conf/httpd.conf

  This is the full path of the httpd.conf file in the Linux system. Find success.
  If the system does not display 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 it may be that the Apache server is not installed in your system. At this time, as long as you have installed the Apache Web server, Then use find / -name httpd.conf to find this configuration file.

  Error free finding tips:

  The "find" command in the Linux system is a command that most system users can use, and is not the patent of the ROOT system administrator. However, ordinary users may also encounter such a problem when using the "find" command, that is, the system administrator ROOT in the Linux system can set certain file directories to the forbidden access mode. In this way, ordinary users do not have permission to use the "find" command to query these directories or files. When ordinary users use the "find" command to query these file directories, the words "Permissiondenied." (forbidden access) often appear. The system will not be able to query the file you want. In order to avoid such errors, we use the method of transferring the error message to try to find the file. Enter
find / -name access_log 2>/dev/null.

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325160037&siteId=291194637