任何人都可以向我解释这个命令行的作用:
find "$dir1" -regex ".*\.exe" -type f -exec cp "{}" "$dir2/my_executable.exe" \;
我想知道为什么这个命令末尾有分号。
非常感谢!
任何人都可以向我解释这个命令行的作用:
find "$dir1" -regex ".*\.exe" -type f -exec cp "{}" "$dir2/my_executable.exe" \;
我想知道为什么这个命令末尾有分号。
非常感谢!
它查找$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"
你最终会找到最后一个文件。这是*.exe
在一个名为$dir1
. $dir2/my_executable.exe
然后每个文件都以每次覆盖的名称复制。所以最终$dir2/my_executable.exe
将与目录中最后找到的.exe
文件相同$dir
。
-type f
=> 仅查找文件-regex ".*\.exe"
=> 查找名称为 with.exe
的文件-exec
=> 对每个找到的文件执行命令{}
=> 表示找到的文件名和路径cp "{}" "$dir2/my_executable.exe"
=> 将找到的文件复制到$dir2/my_executable.exe
\; 终止 exec 语句末尾的分号是 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.