The find command is mainly used to find directories and files, and you can specify multiple parameters for matching. Usage: Search path: Tell find where to search Command parameters: specify the file attributes to be searched, including various attributes, such as type, name, size, modification time, etc. Commonly used parameters:
Output format: The output format is optional. The output formats include -print to print the found content (the default is to print the found content, so it is generally not used), and -exec to further process the found content (more commonly used). The format is:
Examples: find . -maxdepth 1 -name "1.txt" # Directly specify the file name to search, -maxdepth 1 means the maximum search level is the first-level directory find . -maxdepth 1 -name "*.txt" # Search for files ending with .txt in the current directory find . -maxdepth 1 -name "[0-9].txt" # Find txt files named with numbers find . -maxdepth 1 -name "[0-9]*.txt" # Find files starting with a number find . -maxdepth 1 -mtime -5 # Find files in the current directory that have been modified within 5 daysfind . -maxdepth 1 -mtime +5 # Find files in the current directory that have been modified more than 5 daysfind . -maxdepth 1 -type d # Find files of type directory in the current directory, with a maximum search level of one directory (hidden directories will be found) find . -maxdepth 1 -size +10M # Find files larger than 10M in the current directory find . -maxdepth 1 -size -1M # Find files smaller than 1M in the current directory find . -maxdepth 1 -name "[az].txt" -exec rm -rf {} \; # Find txt files named with one letter and delete them find . -maxdepth 1 -name "*.txt" | xargs grep "error" # Print the content of the line with error in the file ending with txt find . -maxdepth 1 -name "*.txt" | xargs rm # Delete files ending with txt in the current directory xargs passes the execution results of the command before the pipeline as parameters one by one to the command after the pipeline ls [az].txt | xargs -n1 -i{} mv {} {}.bak # Add a .bak suffix to the txt files named with a single letter in the current directory. -n1 means to process objects one by one. -i{} replaces the previous object with {}. mv {} {}.bak is equivalent to mv a.txt a.txt.bak Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: How to draw a cool radar chart in CocosCreator
>>: Detailed steps to install Mysql5.7.19 using yum on Centos7
Table of contents Preface iframe implements sandb...
Preface In project development, there are many wa...
First, let me give you an example (if you don’t w...
Table of contents Preface Summary of audio and vi...
What is it? Spring Boot is a sub-project of the S...
Two parameters of Mysql paging select * from user...
MySQL 8.0 compressed package installation method,...
1. HTML Image <img> 1. The <img> tag ...
Development Pain Points During the development pr...
Table of contents Mixin Mixin Note (duplicate nam...
CSS: Copy code The code is as follows: html,body{ ...
I hope to implement some properties of the query ...
Preface I have an old laptop with Win7. In order ...
Use Javascript to implement a message board examp...
Hello everyone, I am Liang Xu. When using Linux, ...