linux command find syntax

1. Find syntax

The find command is used to find files in the specified directory. Any string before the parameter will be regarded as the name of the directory to be searched. If you use this command without setting any parameters, the find command will search for subdirectories and files in the current directory. And display all the subdirectories and files found

find(option)(parameter)

Match according to file or regular expression

Find the file name ending in .txt in the /home directory

find /home -name “*.txt”

Same as above, but ignoring case

find /home -iname “*.txt”

Find all files ending with .txt and .pdf in the current directory and subdirectories

find . ( -name “.txt" -o -name ".pdf” )

or

find . -name “.txt" -o -name ".pdf”

Find out files that do not end with .txt under /home

find /home ! -name “*.txt”

Search by file type

find .-type parameter

f Ordinary file

Search all files that have been accessed in the last seven days

find . -type f -atime -7

Search for all files that have been accessed exactly seven days ago

find . -type f -atime 7

Search all files that have been accessed in more than seven days

find . -type f -atime +7

2, find use

find . -name “fest.txt”

​ -type f/d #File or directory

​ -mtime +30/-2 #30 days ago/2 days

find . -mtime +30 -exec rm -rf {} ;

​ {} introduce the previous result

​ \ End

Accept {-exec (cp rm mv and other commands)

|xargs (rm )

}

example:

find . -type f -name “x.txt” -mtime +2 -exec rm -rf {} ;

find . -type f -name “*Cloud_back_log.txt” -exec cp {} ./ ;

Guess you like

Origin blog.csdn.net/qq_31555951/article/details/107151478