2

任何人都可以向我解释这个命令行的作用:

find "$dir1" -regex ".*\.exe" -type f -exec cp "{}" "$dir2/my_executable.exe" \;

我想知道为什么这个命令末尾有分号。

非常感谢!

4

3 回答 3

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"你最终会找到最后一个文件。
于 2013-11-07T15:04:12.953 回答
2

这是*.exe在一个名为$dir1. $dir2/my_executable.exe然后每个文件都以每次覆盖的名称复制。所以最终$dir2/my_executable.exe将与目录中最后找到的.exe文件相同$dir

  1. -type f=> 仅查找文件
  2. -regex ".*\.exe"=> 查找名称为 with.exe的文件
  3. -exec=> 对每个找到的文件执行命令
  4. {}=> 表示找到的文件名和路径
  5. cp "{}" "$dir2/my_executable.exe"=> 将找到的文件复制到$dir2/my_executable.exe \; 终止 exec 语句
于 2013-11-07T15:04:23.543 回答
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.
于 2013-11-07T15:21:40.120 回答