如何使用find
遍历目录,但不能递归到其子目录?
我试过了-prune
,它不起作用。而且没有-maxdepth
选择。
find /opt/projectname/bin -type f /opt/projectname/bin -prune -o -print
find: missing conjunction
/opt/projectname/bin/file_1_is_printed
/opt/projectname/bin/file_2_is_printed
/opt/projectname/bin/directory_within_bin/some_file_should_not_be_printed
/opt/projectname/bin/directory_2_within_bin/some_file_2_should_not_be_printed
/usr/bin/find:
find.c $Date: 2011/08/12 15:04:36 $Revision: r11.31/4 PATCH_11.31 (PHCO_42158)
libcpio.c $Date: 2008/05/27 16:08:10 $Revision: r11.31/2 PATCH_11.31 (PHCO_36666)
$Revision: @(#) find R11.31_BL2011_0923_2 PATCH_11.31 PHCO_42158
这个问题不是重复的问题。这里没有GNU。尽管该问题可能是重复的问题,但在这些问题上发布的答案要求安装GNU工具。因此,如果这里的答案有助于解决问题,那么这是一个独特的话题。
错误“缺少连词”是因为您在后面重复了目录名称-type f
,find
却不知道如何解析该名称。
为了避免遍历子目录,您需要修剪目录,而不是常规文件。但是,您不得修剪起始目录,否则find
将仅对其进行处理。识别起始目录的一种简单方法是将其名称安排为.
。
find /opt/projectname/bin/. -name . -o -type d -prune -o -print
解释:
-name .
—如果名称是.
,则[不执行任何操作]-type d
—如果文件是目录,请不要进入该目录本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句