In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to find the specified file in the Linux system", the content of the explanation in the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "how to find the specified file in the Linux system"!
-options that must be used by name. Indicates that the system is required to look according to the file name.
General format: find / (dirname)-name filename
Specific file name search method:
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 httpd.conf file is in, or even somewhere on the system, you can use the following command:
Find /-name httpd.conf
Error-free search method:
On Linux systems, system administrator ROOT can set some file directories to disable access mode. In this way, the average user does not have the 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.
Fuzzy file name lookup method:
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, we can also omit the first asterisk, as follows:
Find/etc-name 'srm*'
It is only files like srmyz that can be found.
Find the file in and or out of the way:
The find command can use a hybrid lookup method. For example, if we want to find a file in the / tmp directory that is larger than 100000000 bytes and modified within 48 hours, we can use-and to link the two lookup options together to form a hybrid lookup method.
Find / tmp-size + 10000000c-and-mtime + 2
Use and and or to denote the relationship between and and OR, respectively. Find /-user fred-or-user george
We can interpret this as looking for files belonging to fred or george in the / tmp directory.
You can also use the "not" relationship in the find command to find files. If we want to find all the files that do not belong to panda in the / tmp directory, we can do so with a simple method.
Find / tmp!-user panda
How to find and display files:
Find a file is our purpose, we would like to know the details and attributes of the file found, if we take to find the file now, using the LS command to view the file information is quite tedious, now we can also use the two commands together.
Find /-name "httpd.conf"-ls
As soon as the system finds the httpd.conf file, it displays the httpd.conf file information on the screen.
12063 34-rw-r--r-- 1 root root 33545 Dec 30 15:36 / etc/httpd/conf/httpd.conf
The following table shows some commonly used parameters and methods for finding and displaying file information.
Option usage description
-exec command finds and executes the command
-fprint file print file full file name
-fprint0 file print file full file name including empty file
-fprintf file format print file format
-ok command gives the user the command to perform the operation according to the user's Y confirmation input
-printf format print file format
-ls displays files of the same file format
Query method according to the characteristics of the file:
The following list is some of the criteria for finding the characteristics of a file that can be specified by the find command. Not all the search criteria are listed here. Refer to the relevant books on Linux to know the search functions of all find commands.
-amin n to find the files accessed in the last N minutes of the system
-atime n to find the files accessed by the last 24 hours in the system
-cmin n to find files in the system that were changed in the last N minutes.
-ctime n to find the files in the system whose state was changed in the last 24 hours
-empty looks for blank files in the system, or blank file directories, or folders that do not have subdirectories
-false finds files in the system that are always wrong
-fstype type finds files in the system that exist on the specified file system, for example: ext2.
-gid n to find files in the system where the file number group ID is n
-group gname finds files in the system that belong to the gnam filegroup and specify the group and ID files
For example:
Find /-amin-10 # finds the files accessed in the last 10 minutes of the system
Find /-atime-2 # finds the files accessed in the last 48 hours of the system
Find /-empty # looks for files or folders that are empty in the system
Find /-groupcat # 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 # finds files that have been modified in the last 24 hours of the system
Find /-nouser # finds files that belong to invalid users in the system
Find /-user fred # finds files that belong to the user FRED in the system
For example, if we know that a Linux file size is 1500 bytes, we can use the following command to query find /-size 1500c, and the character c indicates that the size of the file we are looking for is in bytes units. If we don't even know the exact size of this file, we can also use fuzzy lookup in Linux to solve the problem. For example, if we enter the command find/-size + 10000000c, it indicates that our designated system looks up files greater than 10000000 bytes in the root directory and displays them. The "+" in the command requires the system to list only files larger than the specified size, while the use of "-" means that the system is required to list files that are smaller than the specified size.
The control options for the Find command are described:
The Find command also provides users with some unique options to control the lookup operation.
Option usage description
-daystart test system files within 24 hours from today, the usage is similar to-amin
-depth uses the depth-level search process to give priority to finding the contents of files in a specified directory at a certain level
-follow follows wildcard link search; in addition, wildcard link query can also be ignored
-help displays a summary of commands
-maxdepth levels looks in a directory at a certain level according to the decreasing method
-mount is not found in the file system directory and is used in a similar way-xdev.
-noleaf forbids optimal search in non-UNUX file systems, MS-DOS systems, and CD-ROM file systems
-version print version number
After using the-follow option, the find command follows the wildcard link method to find the file. Unless you specify this option, the find command will generally ignore the wildcard link method for file search.
The function of the-maxdepth option is to restrict the find command from searching for files in a directory in a decreasing manner when searching for files beyond a certain level or searching too many directories, which makes the search slower and takes too much time. For example, we want to be in the current (.) To find a file called fred in the directory skill subdirectory, we can use the following command
Find. -maxdepth 2-name fred
If the fred file is in the. / sub1/fred directory, then the command will locate the file directly, and the search will be easy to succeed. If the file is in the. / sub1/sub2/fred directory, then this command cannot be found. Because you have previously given the find command that the maximum query directory level in the directory is 2, you can only find files in the 2-tier directory. The purpose of this is to allow the find command to locate the file more accurately. If you already know the approximate file directory level of a file, adding-maxdepth n will quickly find it in the specified directory.
Thank you for your reading, the above is the content of "how to find the specified file in the Linux system", after the study of this article, I believe you have a deeper understanding of how to find the specified file in the Linux system, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.