我只想在 Linux 中移动文件,我找到了答案这里如下所示:
find . -maxdepth 1 -type f -exec mv {} destination_path \;
这对我来说非常有效。但我的问题是:
\;
这个命令中的含义是什么?此命令中的花括号是否
{}
等效于*
?
答案1
该find
命令假定-exec
选项和;
字符之间的所有内容构成了您想要在每个搜索结果上执行的命令。
由于;
是 shell 中的保留字符bash
,因此您必须使用 对其进行转义\
,否则 bash 将会对其进行解释。man bash
有关详细信息,请参阅。
花括号{}
是 find 的每个搜索结果的占位符。
以下内容摘自的手册页find
:
-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 arguments 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.