我目前正在尝试find(并复制)指定目录中与特定模式匹配的所有文件和文件夹结构,我几乎就在那里!
具体来说,我想从指定的路径递归复制所有不以“_”字符开头的文件夹。
find /source/path/with/directories -maxdepth 1 -type d ! -name _\* -exec cp -R {} /destination/path \;
Run Code Online (Sandbox Code Playgroud)
在 /source/path/with/directories/ 路径中是机器特定的目录,以 '_' 和其他开头,我只对复制其他目录感兴趣。出于某种原因,find 命令返回 /source/path/with/directories/ 目录,因此复制其内容,包括以“_”开头的目录。
任何人都知道为什么会这样?
谢谢,
帕斯卡
小智 20
find返回根路径,因为它符合您的条件——即它是一个目录,并且不以_.
你正在寻找-mindepth 1,我怀疑:
$ cd /tmp
$ mkdir a
$ touch a/b
$ mkdir a/c
$ touch a/c/d
$ find a
a
a/b
a/c
a/c/d
$ find a -mindepth 1
a/b
a/c
a/c/d
Run Code Online (Sandbox Code Playgroud)
参考:查找联机帮助页