了解 linux 中 find-command 中的一些标志

use*_*070 5 linux file-management shell command-line find

我只想在 Linux 中移动文件,我在这里找到了如下答案:

find . -maxdepth 1 -type f -exec mv {} destination_path \;
Run Code Online (Sandbox Code Playgroud)

这对我来说非常有效。但我的问题是

  1. \;此命令中的含义是什么?

  2. {}此命令中的大括号是否等效于*?

NZD*_*NZD 9

find命令假定-exec选项和;字符之间的所有内容都包含您要对每个搜索结果执行的命令。

因为;bashshell 中的保留字符,您必须使用\将其转义,否则 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. 
Run Code Online (Sandbox Code Playgroud)