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 Basic usage of Promise: 1. Crea...
We can view the installation path of mysql throug...
Table of contents What is two-way data binding Im...
1. CSS3 triangle continues to zoom in special eff...
Table of contents 1. Introduction to podman 2. Ad...
Layout part: <div id="slider"> &l...
I believe everyone is familiar with database inde...
This article uses examples to illustrate the prin...
System and user environment design <br />Th...
There is a big difference between the writing ord...
As shown in the figure: Check port usage: sudo ne...
How to view files in a docker image 1. If it is a...
Use nginx to configure the separation of PC site ...
Sometimes some docker containers exit after a per...
1. The relationship between fonts and character d...