shell find exec
时间: 2023-12-22 18:04:09 浏览: 87
exec_shell.patch
The `find` command in shell is used to search for files or directories in a specified location based on certain criteria, such as name, size, type, and date modified. The `exec` option is used with the `find` command to execute a command or a script on each file or directory that matches the search criteria.
The basic syntax of the `find` command with `exec` option is as follows:
```
find /path/to/search -name "filename" -exec command {} \;
```
Here, `/path/to/search` is the location where the search is to be performed, `filename` is the name of the file or directory to be searched for, `command` is the command or script to be executed on each matching file or directory, and `{}` is a placeholder that represents the name of each matching file or directory.
For example, to search for all files with extension `.txt` in the current directory and execute the `ls` command on each file, the following command can be used:
```
find . -name "*.txt" -exec ls {} \;
```
This command will list all the `.txt` files in the current directory and its subdirectories.
阅读全文