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 introduces the directory structure of the search file find command how to use, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
The find command is used to search for files in the directory structure and perform specified actions. This command provides quite a number of search criteria and is very powerful.
Syntax: find [start directory] looks for conditional actions
Description: the find command starts from the specified starting directory, recursively searches its subdirectories, finds files that meet the search criteria and takes relevant actions on them. The search condition provided by this command can be a compound condition consisting of the logical operators not, and, and or. The logical operators and, or, and not mean:
(1) and: logic and, represented by "- a" in the command, is the default option of the system, indicating that the search condition is satisfied only when all the given items are met. For example:
Find-name 'tmp'-xtype c-user' inin'
This command finds all files for which three given conditions are met
(2) or: logical OR, denoted by "- o" in the command. This operator means that the search condition is satisfied as long as one of the given conditions is satisfied. For example:
Find-name 'tmp'-o-name' mina*'
This command queries all files with the file name 'tmp' or match' mina*'.
(3) not: logic is not, use "!" in the command. It means. This operator means to find files that do not meet the given criteria. For example:
Find!-name 'tmp'
This command queries all files whose file name is not 'tmp'.
It is important to note that when many logical options are used, these options can be enclosed in parentheses. In order to avoid the misunderstanding of parentheses caused by Shell itself, the escape character "\" needs to be added before the call sign to remove the meaning of parentheses. Example:
Find\ (- name 'tmp'-xtype c-user' inin'\)
The options for this command mean the following:
First, there are three ways to enter n values in each of the following options, assuming that n is 20:
+ 20 means after 20 (21, 22, 22, 23, etc.)
-20 means before 20 (19, 18, 18, 17, etc.)
20 means exactly 20.
Find by name and file properties.
-name 'string' looks for all files whose file names match the given string. Wildcards *,?, [] are available in the string.
-lname 'string' looks for all symbolic link files whose file names match the given string. Wildcards *,?, [] are available in the string.
-gid n finds all files that belong to the user group with ID number n.
-uid n finds all files belonging to the user with ID number n.
-group 'string' looks for all files that belong to the given string in the user group name.
-user 'string' looks for all files whose user name is the given string.
-empty looks for directories or files of size 0.
-path 'string' finds all files whose pathnames match the given string. Wildcards *,?, [] are available in the string.
-perm permission to find files and directories with specified permissions, which can be represented as 711644.
-size n [bckw] looks for files of the specified file size. The characters after n represent units. The default is b, which represents 512-byte blocks.
-type x looks for a file of type x, where x is one of the following characters:
B block device file
C character device file
D directory file
P named pipe (FIFO)
F ordinary file
L symbolic link file (symbolic links)
S socket file
-xtype x is basically the same as-type, but only looks for symbolic link files.
Search on the condition of time
-amin n finds all files that have been accessed n minutes ago.
-atime n finds all files that have been accessed n days ago.
-cmin n finds all files whose status has been modified n minutes ago.
-ctime n finds all files whose status has been modified n days ago.
-mmin n finds all files whose contents have been modified n minutes ago.
-mtime n finds all files whose contents have been modified n days ago.
Executable action
-exec command name {} executes the given Linux command on files that meet the criteria without asking the user if the command needs to be executed.
{} indicates that the argument to the command is the file found; the end of the command must end with "\;".
The-ok command name {} executes the given Linux command on the eligible file, unlike exec, it asks the user if the command needs to be executed.
-ls lists all the files found in detail.
-fprintf filename writes the found filename to the specified file.
-print displays the found file name on the standard output device.
-for writing in printf format, please refer to the book on C language.
Example of find command instruction:
Find. -name 'main*'-exec more {}\
% finds all files in the current directory that begin with main and displays the contents of those files.
Find. \ (- name a.out-o-name'* .o'\) >-atime + 7-exec rm {}\
Delete all a. Out or * .o files in the current directory that have not been accessed within a week.
"." in% command. Represents the current directory, where find will start from the current directory and look in its subdirectories for files that meet the criteria specified later.
% "\ (" and "\)" denotes parentheses (), where "\" is called escape character. This is written because (and) have a different meaning for Shell, not for the purpose of combining conditions here.
% "- name a.out" refers to looking for a file named a.out
% "- name'* .o'" means to find all files whose names end in .o.
The-o between these two-name indicates logical or (or), that is, to find a file whose name is a.out or whose name ends in .o.
The% find command finds this file in the current directory and its subdirectories, and then determines whether its * * access time was 7 days ago (condition-atime + 7). If so, execute the command rm (- exec rm {}\;) on the file.
Where {} represents the currently found qualified file name, and\; is required by the syntax.
A\ of the * * line in the above command is a continuation character. When the command is too long to write on one line, you can enter a\, and then a > is displayed, instructing the user to continue entering the command.
Is a detailed explanation of the find command to search for files in the directory structure. I hope it will be helpful to you.
Thank you for reading this article carefully. I hope the article "how to use the find command to search files in the directory structure" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.