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/02 Report--
How do I use the find command to find text in Linux? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.
The find command is mainly used to find directories and files, and you can specify a variety of parameters to match.
Usage: find + search path + command parameters [output]
Find path: tell find where to find it
Command parameters: specify the file attributes to be found, including a variety of attributes, such as type, name, size, modification time, and so on.
Commonly used parameters:
-name searches by file name
-user searches according to the owner of the file
-mtime is searched according to the change time of the file.-n means the file modification time is within n days from today, and + n means the file modification time is within n days from today.
-type looks by file type, d for directory, f for file, l for symbolic connection file
-size searches according to the file size (K, M, G). + n M means to find files whose files are larger than n M.
-maxdepth specifies the maximum level at which files are found (default is to search in all subdirectories under the specified path. After specifying the level, you can only find files in first-level or second-level directories)
Output form: the output form is optional, and the output form is-print to print the content found (default will print the found content, so it is generally not used), and-exec to further process the found content (more commonly used) in the form of:
-exec Linux directive {}\; {} represents what is found
Example:
Find. -maxdepth 1-name "1.txt" # specifies the file name lookup directly, and-maxdepth 1 indicates that the maximum lookup level is a first-level directory
Find. -maxdepth 1-name "* .txt" # look for files ending with .txt in the current directory
Find. -maxdepth 1-name "[0-9] .txt" # find a txt file named by a number
Find. -maxdepth 1-name "[0-9] * .txt" # find files that start with a number
Find. -maxdepth 1-mtime-5 # find the modified file find in the current directory within 5 days. -maxdepth 1-mtime + 5 # finds files in the current directory that have been modified for more than 5 days, find. -maxdepth 1-type d # looks for files of type directory in the current directory, up to a hierarchical directory (will look for hidden directories)
Find. -maxdepth 1-size + 10m # finds files larger than 10m in the current directory find. -maxdepth 1-size-1m # find files less than 1m in the current directory
Find. -maxdepth 1-name "[Amurz] .txt"-exec rm-rf {}\; # find the txt file named with one letter and delete the find. -maxdepth 1-name "* .txt" | xargs grep "error" # print the contents of the error line in the file ending with txt find. -maxdepth 1-name "* .txt" | xargs rm # deletes the file at the end of txt in the current directory
Xargs passes the execution result of the command before the pipe as a parameter after the command is passed one by one.
Ls [a mv z] .txt | xargs-N1-I {} mv {}. Bak # adds a .bak suffix to the txt file named after a single letter in the current directory.-N1 means to deal with an object, and-I {} replaces the previous object with {}, which is equivalent to mv a.txt a.txt.bak.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.