繁体   English   中英

Shell-此命令做什么?

[英]Shell - What does this command do?

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

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"您将找到最后一个文件。

这将在名为$dir1的目录中找到所有*.exe文件。 然后,复制每个文件,并以$dir2/my_executable.exe的名称覆盖。 因此,最后$dir2/my_executable.exe将与$dir目录中最后找到的.exe文件相同。

  1. -type f =>仅查找文件
  2. -regex ".*\\.exe" =>查找名称中带有.exe文件
  3. -exec =>在找到的每个文件上执行命令
  4. {} =>代表找到的文件名和路径
  5. 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. 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM