[英]Shell - What does this command do?
Can any body explain to me what this command line do : 任何人都可以向我解释此命令行的作用:
find "$dir1" -regex ".*\.exe" -type f -exec cp "{}" "$dir2/my_executable.exe" \;
And I'd like to know why this command has semi-colon at the end. 我想知道为什么该命令的末尾有分号。
Thanks a lot! 非常感谢!
It looks in $dir
for files with .exe
extension and copies them to $dir2/my_executable.exe
, so that $dir2/my_executable.exe
will end up being the last file found. 它在
$dir
查找扩展名为.exe
文件,并将其复制到$dir2/my_executable.exe
,以便$dir2/my_executable.exe
最终成为找到的最后一个文件。
find "$dir1"
looks for files in $dir1
. find "$dir1"
在$dir1
查找文件。 -regex ".*\\.exe"
having name XXX.exe
. -regex ".*\\.exe"
,名称为XXX.exe
。 -type f
being files -type f
文件 -exec .... {} \\;
performs a command in the files found. cp "{}" "$dir2/my_executable.exe" \\;
copies the found files into "$dir2/my_executable.exe"
. "$dir2/my_executable.exe"
。 As it is always the same, in "$dir2/my_executable.exe"
you will end up having the last file found. "$dir2/my_executable.exe"
您将找到最后一个文件。 This is finding all *.exe
files in a directory named $dir1
. 这将在名为
$dir1
的目录中找到所有*.exe
文件。 Then each of those files are copied with the name of $dir2/my_executable.exe
overwriting it every time. 然后,复制每个文件,并以
$dir2/my_executable.exe
的名称覆盖。 So in the end $dir2/my_executable.exe
will be same as the last found .exe
file in $dir
directory. 因此,最后
$dir2/my_executable.exe
将与$dir
目录中最后找到的.exe
文件相同。
-type f
=> Find only files -type f
=>仅查找文件 -regex ".*\\.exe"
=> find files with the name with .exe
in them -regex ".*\\.exe"
=>查找名称中带有.exe
文件 -exec
=> execute a command on each of the found files -exec
=>在找到的每个文件上执行命令 {}
=> represents found file name with path {}
=>代表找到的文件名和路径 cp "{}" "$dir2/my_executable.exe"
=> copy found file to $dir2/my_executable.exe
and the \\; cp "{}" "$dir2/my_executable.exe"
=>将找到的文件复制到$dir2/my_executable.exe
和\\; terminates the exec statement The semicolon at the end is part of the syntax for the -exec option in the find command: 最后的分号是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.