Shell表示法:找到。 -type f -exec file' {}' \;

时间:2014-01-16 07:02:34

标签: linux bash

这是一个相对简单的命令,所以如果存在重复并且有人可以推荐我,我很抱歉,我将删除/关闭此问题。

查找的手册页

   find . -type f -exec file '{}' \;

   Runs 'file' on every file in or below the current directory.  Notice that the braces are enclosed in single quote marks to protect them from interpretation
   as shell script punctuation.   The semicolon is similarly protected by the use of a backslash, though ';' could have been used in that case also.

我不理解符号\;。这是世界上的什么?

1 个答案:

答案 0 :(得分:5)

在find命令中,操作-exec之后是命令和该命令的参数。因为可以有任意数量的参数,find需要某种方式来知道它何时结束。分号告诉find它已经到达命令参数的末尾。

留给他们自己的设备,大多数贝壳会吃分号。我们希望将分号传递给find命令。因此,我们用反斜杠来逃避它。这告诉shell将分号视为find命令的一个参数。

更多:为什么不呢,有人可能会问,只是假设exec命令的参数只是到了行的末尾?为什么我们需要根据exec命令的参数发出结果?原因是find具有高级功能。例如,考虑一下:

find . -name '*.pdf' -exec echo Yes, we have a pdf: {} \; -o -exec echo No, not a pdf: {}  \;