LinuxFind command usage details

Source: Internet
Author: User
Each operating system is composed of thousands of different types of files. There are system files, user files, shared files, and so on. Sometimes we often forget where a file is stored on the hard disk. Searching for a file in Microsoft's WINDOWS operating system is quite simple,

Each operating system is composed of thousands of different types of files. There are system files, user files, shared files, and so on. Sometimes we often forget where a file is stored on the hard disk. Searching for a file in Microsoft's WINDOWS operating system is quite simple. you only need to click "Start"-"search" on the desktop, and then you can find a file on the local hard disk in various ways, local network, and even search for various files and documents on the INTERNET.

However, users who use Linux are not so lucky. finding a file on Linux is really troublesome. After all, in Linux, we need to use a dedicated "search" command to find files on the hard disk. The file expression format in Linux is very complex. Unlike WINDOWS, the file expression format in DOS is a unified AAAAAAA. the BBB format is so easy to find. in WINDOWS, you only need to know the file name or suffix of the file to be searched. In Linux, the command for searching files is usually the "find" command. the "find" command can help us find the files we need in Linux routine transactions. For New Linux users, the "find" command is also a method to understand and learn the characteristics of Linux files. Due to the wide variety of Linux releases and fast version upgrades, Linux books often state the location of a configuration file, which is often not available for new Linux users. For example, REDHAT Linux 7. O and REDHAT in Linux 7.1, the hard disk location and file directory of some important configuration files have changed a lot. if you do not learn to use the "find" command, it is quite difficult to find a configuration file among thousands of Linux files. I have suffered this kind of hardship before being proficient in the "find" command. The following describes in detail how to use and use the powerful "find" command.
Each operating system is composed of thousands of different types of files. There are system files, user files, shared files, and so on. Sometimes we often forget where a file is stored on the hard disk. Searching for a file in Microsoft's WINDOWS operating system is quite simple. you only need to click "Start"-"search" on the desktop, and then you can find a file on the local hard disk in various ways, local network, and even search for various files and documents on the INTERNET.

However, users who use Linux are not so lucky. finding a file on Linux is really troublesome. After all, in Linux, we need to use a dedicated "search" command to find files on the hard disk. The file expression format in Linux is very complex. Unlike WINDOWS, the file expression format in DOS is a unified AAAAAAA. the BBB format is so easy to find. in WINDOWS, you only need to know the file name or suffix of the file to be searched. In Linux, the command for searching files is usually the "find" command. the "find" command can help us find the files we need in Linux routine transactions. For New Linux users, the "find" command is also a method to understand and learn the characteristics of Linux files. Due to the wide variety of Linux releases and fast version upgrades, Linux books often state the location of a configuration file, which is often not available for new Linux users. For example, REDHAT Linux 7. O and REDHAT in Linux 7.1, the hard disk location and file directory of some important configuration files have changed a lot. if you do not learn to use the "find" command, it is quite difficult to find a configuration file among thousands of Linux files. I have suffered this kind of hardship before being proficient in the "find" command. The following describes in detail how to use and use the powerful "find" command.

Search by file name:
This method is as easy to understand as searching for files in WINDOWS. If you put this file in a single folder, you can easily find it by using the common "ls" command, using the "find" command to search for it will not impress you. after all, the "find" command has more powerful functions than this. If you know the file name of a file, but do not know the folder to which the file is put, or even layers of embedded folders. For example, if you forget the directory in which the httpd. conf file is located, or even somewhere in the system, you can run the following command:
Find/-name httpd. conf

This command syntax looks easy to understand, that is, write-name directly after find, indicating that the system is required to search by file name, and finally write the target file name httpd. conf. Wait a moment and the system will display the search result list on the computer screen:
Etc/httpd/conf/httpd. conf

This is the complete path of the httpd. conf file in Linux. Search successful.
If the system does not display the result after you enter the preceding search command, do not assume that the system has not executed the find/-name httpd command. conf command, but it may be that the Apache server is not installed in your system. if you have installed the Apache Web server, then use find/-name httpd. conf to find the configuration file.

No error search skills:
In Linux, the "find" command is a command that most system users can use. it is not the patent of the ROOT system administrator. However, common users may encounter this problem when using the "find" command, that is, the system administrator ROOT in Linux can set some file directories to the access prohibited mode. In this way, normal users do not have the permission to use the "find" command to query these directories or files. When a common user uses the "find" command to query the directories of these files, the words "Permissiondenied." (access prohibited) appears. The system will not be able to query the files you want. To avoid such errors, we tried to find the file and input
Find/-name access_log 2>/dev/null

This method transfers the search error prompt to a specific directory. After the system executes this command, the error information is directly transmitted to stderrstream 2. access_log 2 indicates that the system will send the error information to stderrstream 2, /dev/null is a special file that indicates null or error information. in this way, the queried error information will be transferred and will not be displayed.

In Linux, you may encounter such a problem when searching for files. If we look for a file on the entire hard disk, it will take a long time to find a file in this system, especially for large Linux systems and large-capacity hard disks, when the file is placed in a very deep directory. If we know that this file is stored in a large directory, it can save a lot of time as long as we find it in this directory. Use find/etc-name httpd. conf to solve this problem. The preceding command is used to query the httpd. conf file in the etc directory. Here we will describe the meaning of the "/" function symbol. if "find/" is input, it indicates that the Linux system is required to search for files in the entire ROOT directory, that is, to search for files on the entire hard disk, while "find/etc" is to find files only under the etc directory. Because "find/etc" indicates that files are only searched in The etc directory, the search speed is much faster.

Method for searching based on some file names:
This method is the same as finding known file names in WINDOWS. However, in Linux, searching for files based on some file names is much more powerful than similar searching methods in WINDOWS. For example, if we know that a file package contains the three letters of srm, we can find all the files in the system that contain the three letters. enter:
Find/etc-name * srm *

This command indicates that the Linux system will find all files containing the three letters srm in the/etc directory, such as absrmyz and tibc. srm and other qualified files can be displayed. If you know that the file is prefixed by the srm letters, you can also omit the asterisks. the command is as follows:
Find/etc-name srm *

Only files such as srmyz are found. files such as absrmyz and absrm do not meet the requirements and are not displayed. This greatly improves the efficiency and reliability of file searching.

Query methods based on File features:
If you only know the size of a file, modify the date and other features, you can also use the "find" command to find out, which is basically the same as the "search" function in WINDOWS. In Microsoft's "search" in WINDOWS, "search assistant" makes searching for files and folders, printers, users, and other computers on the network easier. It makes searching on the Internet easier. The search assistant also includes an index service that maintains the indexes of all files in the computer, making the search faster. When you use "search assistant", you can specify multiple search criteria. For example, you can search for files and folders by name, type, and size. You can even search for files containing specific text. If you are using Active Directory, you can also search for a printer with a specific name or location.

For example, if we know that the size of a Linux file is 1,500 bytes, we use the following command to query find/-size 1500c. character c indicates that the size of the file to be searched is measured in bytes. If we do not know the specific size of this file, we can perform fuzzy search in Linux. For example, if we enter the find/-size + 0000000c command, it indicates that we specify the system to find the file larger than 10000000 bytes in the root directory and display it. The "+" command requires the system to list only files larger than the specified size, and the "-" command requires the system to list files smaller than the specified size. The following list is the search action performed by the system after different "find" commands are used in Linux. From this, we can easily see that there are many ways to use the "find" command in Linux, the "find" command does not need to be used in WINDOWS to find files flexibly.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.