How to find a file location under Linux

Source: Internet
Author: User

I. Using the file name lookup method:

For example, suppose you forget httpd.conf the file is in the directory of the system, even if it is not known somewhere in the system, then this command can be used as follows: Find/-name httpd.conf This command syntax seems to be easy to understand, is directly behind find write-name, indicating that the system according to the file name, and finally write httpd.conf the target file name can be. Wait a minute. The system displays a list of search results on the computer screen: etc/httpd/conf/httpd.conf This is the full path to the httpd.conf file on the Linux system.   Find success. If the system does not show results after entering the Find command above, do not assume that the system does not have a Find/-name httpd.conf command, and that the Apache server may not be installed on your system, as long as you install the Apacheweb server and then use the Find /-name httpd.conf will be able to find this configuration file.

two. No error finding tips:

Find/-name access_log 2>/ Dev/null This method is to transfer the lookup error prompt to a specific directory. After the system executes this command, the information that encounters the error is sent directly to the STDERRSTREAM2, ACCESS_LOG2 is that the system will send the error message to STDERRSTREAM2,/dev/null is a special file, indicating empty or wrong information,   The error message that is queried will be shifted and will not be displayed again. Finding files on a Linux system also encounters such a practical problem. If we're on the entire hard drive, it's going to take a long time to find a file in this system, especially for large Linux systems and larger hard disks, where files are placed in deep-nested directories. If we know that this file is stored in a large directory, you can save a lot of time by looking down in this directory. Use find/etc-name  httpd.conf to solve this problem. The above command indicates that the httpd.conf file is queried in the ETC directory. Here again "/" The meaning of this function symbol, if the input "find/" means that the Linux system is required to find the entire root directory file, that is, the entire hard disk to find files, and "Find/etc" is only in the ETC directory to find files. Because "find/etc" means to find files only in the ETC directory, the speed of the lookup is much faster.

Three. Find the method according to the partial file name:

For example, if we know that a file contains 3 letters of SRM, it is possible to find all the files containing these 3 letters in the system, and enter: find/etc-name ' *srm* ' This command indicates that the Linux system will etc The entire directory to find all the files containing the SRM 3 letters, such as ABSRMYZ,TIBC.SRM, and so on, can be displayed in the eligible files. If you also know that this file starts with SRM 3 letters, then we can omit the first asterisk, the command is as follows: Find/etc-name ' srm* ' This is only a file like Srmyz is found, Files such as Absrmyz or ABSRM do not meet the requirements and are not displayed, so the efficiency and reliability of finding files is greatly enhanced.

Four. According to the characteristics of the file Query method:      

If you only know the size of a file, features such as modified date can also be found using the "find" command, which is essentially the same as the "search" feature in Windows systems. In Microsoft's search, Search Companion makes it easier to search for files and folders, printers, users, and other computers on the network. It even makes searching on the Internet much easier. The Search Companion also includes an Indexing service that maintains an index of all the files in the computer, making the search faster. When you use Search Companion, 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 the user is using active Directory, you can also search for a printer with a specific name or location. For example, we know a Linux file size of 1,500bytes, then we use the following command to query the find/-size 1500c, the character C indicates that the size of the file to find is in bytes units. If we do not know the exact size of this file, then in Linux can also be used in the fuzzy search method to solve. For example, we enter the Find/-size+10000000c command, which indicates that we specify that the system finds files larger than 10000000 bytes in the root directory and displays them. The "+" in the command indicates that the system only lists files larger than the specified size, while using "-" indicates that the system is required to list files smaller than the specified size. The following list is the system's look-up action after Linux uses a different "find" command, which makes it easy to see how the "find" command is used in Linux in many ways, with the "find" command looking for a file that is as flexible as it can be in Windows.

Find/-amin-10 # finds files accessed in the last 10 minutes of the system

Find/-atime-2 # finds files accessed in the last 48 hours of the system

Find/-empty # finds files or folders that are empty in the system

Find/-group Cat # finds files that belong to Groupcat in the system

Find/-mmin-5 # finds files that have been modified in the last 5 minutes of the system

Find/-mtime-1 #查找在系统中最后24小时里修改过的文件

Find/-nouser #查找在系统中属于作废用户的文件

Find/-user Fred #查找在系统中属于FRED这个用户的文件

The following list is part of the criteria for finding the characteristics of a file that can be specified by the Find command. There are no search criteria listed here, so refer to the Find function of all find commands for Linux-related books.

-amin N Find the last n minutes of files accessed in the system

-atime N Find the last n*24 hour Access file in the system

-cmin N Find the last n minutes in the system changed state of the file

-ctime N Find the last n*24 hour in the system changed state file

-empty find a blank file 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 finds files in the system that exist on the specified file system, for example: ext2.

-gid n Find file with file Number group ID N in the system

-group gname Find files in the system that belong to the Gnam filegroup, and specify the group and ID of the file.

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.