任何机构都可以向我解释这个命令行的用途:
find "$dir1" -regex ".*\.exe" -type f -exec cp "{}" "$dir2/my_executable.exe" \;
我想知道为什么这个命令最后有分号。
非常感谢!
答案 0 :(得分:2)
在$dir
中查找包含.exe
扩展名的文件并将其复制到$dir2/my_executable.exe
,以便$dir2/my_executable.exe
最终成为找到的最后一个文件。
find "$dir1"
在$dir1
。-regex ".*\.exe"
名称为XXX.exe
。-type f
是文件-exec .... {} \;
在找到的文件中执行命令。cp "{}" "$dir2/my_executable.exe" \;
将找到的文件复制到"$dir2/my_executable.exe"
。因为它始终是相同的,所以在"$dir2/my_executable.exe"
中,您最终会找到最后一个文件。答案 1 :(得分:2)
这是在名为*.exe
的目录中查找所有$dir1
个文件。然后每次复制名称为$dir2/my_executable.exe
的每个文件都会覆盖它。因此,最后$dir2/my_executable.exe
将与.exe
目录中最后找到的$dir
文件相同。
-type f
=>仅查找文件-regex ".*\.exe"
=>查找名称中包含.exe
的文件-exec
=>对每个找到的文件执行命令{}
=>表示找到的带路径的文件名cp "{}" "$dir2/my_executable.exe"
=>将找到的文件复制到$dir2/my_executable.exe
和\;终止exec语句答案 2 :(得分:1)
末尾的分号是find命令中-exec选项语法的一部分:
-exec command ; Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of `;' is encountered. The string `{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in argu‐ ments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a `\') or quoted to protect them from expansion by the shell. See the EXAMPLES section for examples of the use of the -exec option. The specified command is run once for each matched file. The command is executed in the starting directory. There are unavoidable security problems surrounding use of the -exec action; you should use the -execdir option instead.