Bash:使用绝对路径修剪查找结果
Bash: Prune find results using absolute paths
我正在 运行ning 一个脚本来查看一些文件夹中的文件类型,但我需要 p运行e 几个文件夹。当我使用相对文件路径通过 PuTTy 运行 脚本工作时,但是当我添加绝对文件路径以便我可以 运行 它作为 cron 任务时,它不会 p运行 e 正确。
这是我的命令:
/bin/find . -not \( -path "./Ready" -prune \) -not \( -path "./Loading" -prune \) -not \( -path "./Backups" -prune \) -name "*.txt"
但是,当我用完整路径替换“./”时,returns 会在不应搜索的文件夹中找到文件。
有什么想法吗?提前致谢。
Note that the pattern match test applies to the whole file name,
starting from one of the start points named on the command line. It
would only make
sense to use an absolute path name here if the relevant start point is also an absolute path. This means that this command
will never match anything:
find bar -path /foo/bar/myfile -print
您也需要使用绝对路径作为搜索基础,因此请将第一个 .
(搜索的起点)与用于 -path
参数的相同绝对路径交换。
find /usr -path "/usr/src/linux*" -prune -o -path "/usr/inclu*" -prune -o -name "*.txt" -print
这将列出所有 *.txt
文件,但不包括任何以 /usr/src/linux*
或 /usr/inclu*
.
开头的目录的内容
我正在 运行ning 一个脚本来查看一些文件夹中的文件类型,但我需要 p运行e 几个文件夹。当我使用相对文件路径通过 PuTTy 运行 脚本工作时,但是当我添加绝对文件路径以便我可以 运行 它作为 cron 任务时,它不会 p运行 e 正确。
这是我的命令:
/bin/find . -not \( -path "./Ready" -prune \) -not \( -path "./Loading" -prune \) -not \( -path "./Backups" -prune \) -name "*.txt"
但是,当我用完整路径替换“./”时,returns 会在不应搜索的文件夹中找到文件。
有什么想法吗?提前致谢。
Note that the pattern match test applies to the whole file name, starting from one of the start points named on the command line. It would only make sense to use an absolute path name here if the relevant start point is also an absolute path. This means that this command will never match anything:
find bar -path /foo/bar/myfile -print
您也需要使用绝对路径作为搜索基础,因此请将第一个 .
(搜索的起点)与用于 -path
参数的相同绝对路径交换。
find /usr -path "/usr/src/linux*" -prune -o -path "/usr/inclu*" -prune -o -name "*.txt" -print
这将列出所有 *.txt
文件,但不包括任何以 /usr/src/linux*
或 /usr/inclu*
.