Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the find command in Linux

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use the find command in Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Each operating system is made up of thousands of different kinds of files. Among them, there are files that come with the system itself, users' own files, and shared files, and so on. We sometimes forget where a file is on our hard drive. It is quite easy to find a file in Microsoft's WINDOWS operating system. Just click "start"-"search" on the desktop and you can find all kinds of files and documents on your local hard disk, local area network, and even INTERNET in various ways.

However, users who use Linux are not so lucky, and it is really troublesome to find a file on Linux. After all, in Linux, we need to use a special "find" command to find files on the hard drive. The file expression format under Linux is very complex, unlike the unified AAAAAAA.BBB format under WINDOWS,DOS, which is so easy to find. In WINDOWS, it is very easy to find as long as you know the file name or suffix of the file you are looking for. The command to find files in Linux is usually the find command, and the find command can help us to find out the files we need in the daily affairs of using and managing Linux. For novices to Linux, the find command is also a way to understand and learn the characteristics of Linux files. Because there are many Linux distributions and version upgrades are very fast, Linux books often specify the location of a configuration file, and often novice Linux users follow clues to find it or can't find it. For example, REDHAT Linux 7.o and REDHAT Linux 7.1where some important configuration files are located in the hard disk location and file directory have been greatly changed, if you do not learn to use the find command, then in thousands of Linux files to find one of the configuration files is very difficult, the author has not mastered the find command before the suffering. OK, here is a detailed introduction to all the uses and uses of the powerful find command.

Each operating system is made up of thousands of different kinds of files. Among them, there are files that come with the system itself, users' own files, and shared files, and so on. We sometimes forget where a file is on our hard drive. It is quite easy to find a file in Microsoft's WINDOWS operating system. Just click "start"-"search" on the desktop and you can find all kinds of files and documents on your local hard disk, local area network, and even INTERNET in various ways.

However, users who use Linux are not so lucky, and it is really troublesome to find a file on Linux. After all, in Linux, we need to use a special "find" command to find files on the hard drive. The file expression format under Linux is very complex, unlike the unified AAAAAAA.BBB format under WINDOWS,DOS, which is so easy to find. In WINDOWS, it is very easy to find as long as you know the file name or suffix of the file you are looking for. The command to find files in Linux is usually the find command, and the find command can help us to find out the files we need in the daily affairs of using and managing Linux. For novices to Linux, the find command is also a way to understand and learn the characteristics of Linux files. Because there are many Linux distributions and version upgrades are very fast, Linux books often specify the location of a configuration file, and often novice Linux users follow clues to find it or can't find it. For example, REDHAT Linux 7.o and REDHAT Linux 7.1where some important configuration files are located in the hard disk location and file directory have been greatly changed, if you do not learn to use the find command, then in thousands of Linux files to find one of the configuration files is very difficult, the author has not mastered the find command before the suffering. OK, here is a detailed introduction to all the uses and uses of the powerful find command.

Look up through the file name:

This method is as easy to understand as looking up files under WINDOWS. If you put this file in a single folder, you can easily find it using the common "ls" command, then using the find command to find it will not impress you, after all, the find command is more powerful than that. If you know the file name of a file, but do not know which folder the file is placed in, or even layers of nesting folders. For example, if you forget which directory the file httpd.conf is in, or even somewhere on the system, you can use the following find command:

Find /-name httpd.conf

The syntax of this command seems easy to understand, just write-name after the find command, indicating that the system is required to look up the file name by file name, and * write the target file name httpd.conf. In a moment, 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 file httpd.conf in the Linux system. The search was successful.

If the system does not display the results after entering the above search command, then do not think that the system does not execute the find/-name httpd.conf command, but may not have an Apache server installed in your system, as long as you install the Apache Web server, and then use find/-name httpd.conf to find this configuration file.

Error-free finding techniques:

Find command is a command that can be used by most system users in Linux system, and it is not the patent of ROOT system administrator. However, the average user may encounter this problem when using the find command, that is, the system administrator ROOT in the Linux system can set some file directories to disable access mode. In this way, the average user does not have permission to query these directories or files with the find command. When the average user uses the find command to query these file directories, the words "Permissiondenied." (forbidden) often appear. The system will not be able to query the file you want. To avoid such errors, we can use the method of transferring the error prompt to try to find the file and type

Find /-name access_log 2 > / dev/null

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

Finding files in the Linux system will also encounter such a practical problem. If we look for a file on the entire hard drive, it will take a long time to find a file in this system, especially on large Linux systems and larger hard drives, where the files are placed in deeply nested directories. If we know that this file is stored in a large directory, we can save a lot of time by looking down in this directory. You can solve this problem by using find / etc-name httpd.conf. The above command is to query the httpd.conf file in the etc directory. Here again explain the meaning of the "/" function symbol, if you enter "find/" means that the Linux system is required to look for files in the entire ROOT directory, that is, to look for files on the entire hard disk, while "find/etc" is only looking for files in the etc directory. Because "find/etc" means to look for files only in the etc directory, the search speed is much faster.

Find the method based on some file names:

This method is the same as looking up a known file name in WINDOWS. However, the method of finding files based on partial filenames in Linux is much more powerful than similar methods in WINDOWS. For example, if we know that a file contains the letters srm, it is possible to find all the files in the system that contain these three letters. Enter:

Find / etc-name'* srm*'

This command indicates that the Linux system will search the entire / etc directory for all files containing the three letters srm, such as absrmyz, tibc.srm, and other eligible files can be displayed. If you also know that the file starts with the letters srm, then we can also omit the first asterisk, the find command is as follows:

Find/etc-name 'srm*'

Only files like srmyz can be found, and files like absrmyz or absrm do not meet the requirements and are not displayed, so the efficiency and reliability of finding files are greatly enhanced.

Query method according to the characteristics of the file:

If you only know the size of a file, the modification date and other features can also be found using the find command, which is basically the same as the "search" function in the WINDOWS system. The "search assistant" in WINDOWS in Microsoft's search makes it easier to search for files and folders, printers, users, and other computers on the network. It even makes it easier to search on Internet. Search Assistant also includes an indexing service that maintains indexes of all files on your computer, making searches faster. When using search Assistant, users can specify multiple search criteria. For example, users can search for files and folders by name, type, and size. Users can even search for files that contain specific text. If you are using Active Directory, you can also search for printers with a specific name or location.

The above is all the contents of this article entitled "how to use find commands in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report