[英]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
文件相同。
-type f
=>仅查找文件 -regex ".*\\.exe"
=>查找名称中带有.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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.