The exec explain

-execThe argument is followed by
commandCommand, whose termination is by; Is the end of the command, so the semicolon after the command is indispensable, considering that the semicolon will have different meanings on different systems, so the front is used with a backslash.

{}The curly braces represent the filename previously found by find.

When you use find, you can use it by simply writing the desired operation in a file
execTo cooperate with
findIt’s easy to find. In some operating systems only
-execOptions such as
ls -lSuch an order. Most users use this option to find old files and delete them. It is recommended that before actually executing the rm command to delete files, it is best to look at them with the ls command to make sure that they are the files to be deleted.
execOptions are followed by a command or script to execute, followed by a pair
{}, a space and a space
\, and finally a semicolon. In order to use
execOptions, must be used together
printOptions. And if you check that out
findCommand, you will see that the command only prints the relative path and filename from the current path.

Finds all properties in the current directory.txtFile and print out the detailed file information

> find . -type f -name "*.txt" -exec ls -l {} \;

Find the contents of the current directory modified 30 days ago.logFile and delete

> find . -type f -name "*.log" -mtime +30 -exec rm {} \;

shellBefore deleting a file by any means, be careful to look at the corresponding file! When used such as
rmCommand, can be used
-execOptions for the safe mode. It will prompt you before acting on each matched file.

Find the contents of the current directory modified 30 days ago.logFile and delete, give a prompt before deletion

> find . -type f -name "*.log" -mtime +30 -ok rm {} \;

In the above example, the find command looks for all files in the current directory whose names end in.log and have changed more than 30 days ago, and deletes them, albeit with a prompt before deleting them. Press Y key to delete the file, press N key not to delete.


> find / -name "passwd*" -exec grep "root" {} \;

Any form of command can be used in the -exec option. In the example above we use the grep command. The find command first matches all file names
passwd*And then execute the grep command to see if a root user exists in any of these files

Find all the files in the current directory.logFile and move to the specified directory

> find . -name "*.log" -exec mv {} .. /rumenz \;

The original link:… WeChat official account: entry station