linux -exec
时间: 2023-09-21 15:11:24 浏览: 98
The `exec` command in Linux is used to execute a command or a series of commands on a set of files or directories. It is mostly used in conjunction with the `find` command to perform actions on the files or directories found by `find`.
The basic syntax of the `exec` command is as follows:
```
find <directory> <options> -exec <command> {} \;
```
Here, `find` is used to locate the files or directories that meet certain criteria specified by `<options>`. The `-exec` option is used to execute a command on each of the files or directories found by `find`. The `{}` placeholder is used to represent each file or directory, and the `\;` indicates the end of the command.
For example, to find all the files with the `.txt` extension in the current directory and delete them, you can use the following command:
```
find . -name "*.txt" -type f -exec rm {} \;
```
This will find all the files with the `.txt` extension in the current directory and its subdirectories, and delete them using the `rm` command.
阅读全文