The following is a complementary part of the video course, and to learn more about Linux commands, you can learn from the following links:
Http://edu.51cto.com/course/13070.html
By file name Lookup method:
This method is as easy to understand as finding a file under Windows. If you put this file in a single folder, as long as the common "ls" command can be easily found out, then use the "find" command to find it can not impress you, after all, "find" command the powerful function of more than this. If you know the file name of a file, you do not know which folder to put the file into, or even a nested folder in layers. 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, it is possible to use the following command:
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. Hold on a second. 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 in the Linux system. Find success.
If the system does not show results after entering the above lookup command, do not assume that the system does not have the find/-name httpd.conf command, and that the Apache server may not be installed on your system, as long as you install the Apache Web server and then use the Find /-name httpd.conf will be able to find this configuration file.
No Error finding tips:
The "find" command in a Linux system is a command that most system users can use, not a root system administrator's patent. However, it is also possible for ordinary users to use the "find" command, which means that the system administrator root in the Linux system can set some file directories to block access mode. This way, ordinary users do not have the right to use the "find" command to query these directories or files. When ordinary users use the "find" command to query these file directories, the "permissiondenied." will often appear. (No access) words. The system will not be able to query the file you want. To avoid such errors, we tried to find the file by using the method of transfer error, enter
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 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 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.
Find methods based on partial file names:
This method is the same as finding the known file name method in Windows. However, it is much more powerful to find a file in Linux based on a partial file name than in a similar lookup method in Windows. For example, we know that a file contains 3 letters of SRM, so 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 find all the files containing the SRM 3 letters in the/etc directory, such as Absrmyz, TIBC.SRM and so on, which can be displayed. 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, such as Absrmyz or ABSRM files are not meet the requirements, not be displayed, so the efficiency and reliability of the search file is greatly enhanced.
Based on 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. Search Companion in Windows in Microsoft Search makes it easier to search for files and folders, printers, users, and other computers on your 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,500 bytes, 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. 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, if we enter find/-size +10000000c This command, we indicate 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 different "find" commands, and it's easy to see how the "find" command is used in Linux in many ways, with the "find" command looking for a file that is flexible to use and does not necessarily have a poor ability to find 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
finds files accessed in the last N minutes of the system
-atime n
Find the last n 24-hour files in the system
-cmin n
Find files in the last n-minute changed state of the system
-cti Me n
Find the last n 24-hour file in the system
-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 files in the system with a number group ID of n
-group gname
Find files in the system that belong to the Gnam filegroup, and specify the group and ID files
Control options for the Find command description: The
Find command is also provided to the user for a Specific options to control the find operation. The following table summarizes the most basic, most commonly used find command control options and their usage.
Options
uses a description of
-daystart
. Test system from today to 24 hours from the file, usage similar to-amin
-depth
Use the depth level of the lookup process, in a certain level of the specified directory to first find file content
-follow
Follow the linked connection method, or ignore the linked connection query
-help
Show command Summary
-maxdepth levels
Find in a hierarchy of directories by decreasing method
-mount The
is not located in the file system directory, and is similar to-xdev.
-noleaf
prohibits optimization in a non-unux file system, MS-DOS system, CD-ROM file system find
-version
Print version number
With the-follow option, the Find command follows the wildcard linked, and unless you specify this option, the Find command will generally ignore the linked connection for file lookups.
The purpose of the-maxdepth option is to limit the Find command to search for files over a certain level or to search for too many directories in a directory in descending order, which results in slower lookups and too much time spent searching. For example, we want to have the current (.) Directory tricks subdirectory Find a file named Fred, we can use the following command
Find. -maxdepth 2-name Fred
If this Fred file is in the./sub1/fred directory, then this command will directly locate the file and find it easy to succeed. If this file is in the./sub1/sub2/fred directory, then this command cannot be found. Because the Find command is already given the largest query directory level in the directory at 2, only files in the 2-tier directory can be found. The purpose of this is to get the Find command to locate the file more precisely, if you already know the file directory of the approximate file size, then the addition of-maxdepth N will soon be able to find success in the specified directory.
Find a file using a hybrid lookup method
The find command can use a hybrid lookup method, for example, if we want to find a file that is larger than 100000000 bytes in the/tmp directory and modified within 48 hours, we can use-and to combine the two find-and-select items together into a mixed lookup.
Find/tmp-size +10000000c-and-mtime +2
Friends who have studied computer language know that in computer language, the relationship between "and" and "or" is expressed by using and, respectively. Common in search commands for Linux systems.
There are examples of this,
Find/-user Fred-or-user George
We can explain to find files belonging to the two users of Fred or George in the/tmp directory.
You can also use a "non" relationship to find files in the Find command, if we want to find all files in the/tmp directory that are not part of panda, use a simple
Find/tmp! -user Panda
The command will be solved. Very simple.
Ways to find and display files
Finding a file is our goal, we would like to know the details and properties of the found file, if we take the present find file, in using the LS command to view the file information is quite cumbersome, now we can also combine these two commands to use.
Find/-name "httpd.conf"-ls
The httpd.conf file information is displayed on the screen immediately after the system finds the httpd.conf file.
12063 34-rw-r--r--1 root root 33545 Dec 15:36/etc/httpd/conf/httpd.conf
The following table is a list of commonly used find files and displays the parameters and usage of file information
Options
Description of Use
-exec command;
Find and Execute commands
-fprint file
Print file full filename
-fprint0 file
Print files full file name including empty files
-fprintf file format
Print file format
-OK command;
Perform actions on user commands, according to the user's Y acknowledgment input
-printf format
Print file format
-ls
Print files of the same file format.
Linux Find command