In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the usage of find grammar in Linux". In daily operation, I believe that many people have doubts about the usage of find grammar in Linux. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the usage of find grammar in Linux". Next, please follow the editor to study!
The find syntax is as follows:
Find (option) (parameter)
Common examples
Find by file name
Lists all files in the current directory and subdirectories
Find.
Find the file named 11.png in the current directory
Find. -name "11.png"
Find all the jpg files in the current directory
Find. -name "* .jpg"
Find the jpg file and png file in the current directory
Find. -name "* .jpg"-o-name "* .png"
Find files in the current directory that do not end in png
Find. !-name "* .png"
Find according to regular expression
Note: regular expressions are more complex than previously thought and support several types. You can refer to here
Find the png file in the current directory with numeric file names.
Find. -regex "\. / * [0-9] +\ .png"
Find according to the path
Find the file / path that contains wysiwyg in the path in the current directory.
Find. -path "* wysiwyg*"
Find by file type
Filter file types through-type.
F ordinary file
L symbolic connection
D directory
C character device
B block equipment
S socket
P Fifo
For example, find the files in the current directory that contain wysiwyg in the path.
Find. -type f-path "* wysiwyg*"
Limit the depth of search
Find all the png in the current directory, not including subdirectories.
Find. -maxdepth 1-name "* .png"
Correspondingly, there is also the mindepth option.
Find. -mindepth 2-maxdepth 2-name "* .png"
Based on file size
Filter the file size through-size. The supported file size units are as follows
B-block (512 bytes)
C-byte
W-word (2 bytes)
K-kilobytes
M-megabytes
G-gigabyte
For example, find files with a file size of more than 100m in the current directory
Find. -type f-size + 100m
According to access / modification / change time
The following time types are supported.
Access time (- atime/ days,-amin/ minutes): the last time the user visited.
Modification time (- mtime/ days,-mmin/ minutes): one modification time for the file *.
Change time (- ctime/ days,-cmin/ minutes): file data elements (such as permissions, etc.) * a modification time.
For example, find out the files that have been modified within 1 day
Find. -type f-mtime-1
Find out the files that have been accessed in the last week
Find. -type f-atime-7
Move the log files in the log directory for more than a week to / tmp/old_logs.
Find. -type f-mtime + 7-name "* .log"-exec mv {} / tmp/old_logs\
Note: {} is used in conjunction with the-exec option to match all files, which is then replaced with the appropriate file name.
In addition,\; is used to indicate the end of the command, and if it is not added, there will be the following prompt
Find:-exec: no terminating ";" or "+"
According to the authority
Through-perm to achieve. For example, find files with permissions of 777 in the current directory
Find. -type f-perm 777
Find out the php files in the current directory whose permissions are not 644.
Find. -type f-name "* .php"!-perm 644
According to the file owner
Find out the file whose owner is root
Find. -type f-user root
Find out the files whose group is root
Find. -type f-group root
Execute the command when the file is found
Through-ok, and-exec to achieve. The difference is that-ok will confirm twice before executing the command, and-exec will not.
Take a look at the actual example. Delete all js files in the current directory. The effect of using-ok is as follows. There is a second confirmation before deletion.
➜find find. -type f-name "* .js"-ok rm {}\; "rm. / 1.js"?
Try it-exec. Just delete it.
Find. -type f-name "* .js"-exec rm {}\
Find the empty file
Examples are as follows
Touch {1.. 9} .txt echo "hello" > 1.txt find. -empty at this point, the study of "the usage of find grammar in Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.