bash / find :查找位于上述目录中的文件

问题描述 投票:0回答:2

以下脚本尝试搜索与模式匹配的文件并将其复制到当前目录

   #pattern to search
    lig="lig*"
    output=$(pwd)
    # find in anywhere and copy to the current dir
    find -maxdepth 1 ../../ -name "${lig}*.png" -exec cp "{}" ${output}  \;

find找不到路径的问题:

find: paths must precede expression: `../../'
find: possible unquoted pattern after predicate `-maxdepth'?

在我的情况下,我需要在当前目录上方的某个位置查找 $lig,即

/home/user/Bureau/Analyse/BCL_MDtest_haddock2/Analysis

文件 lig* 位于

/home/novikov-g/Bureau/Analyse/BCL_MDtest_haddock2/!plots

如何定义当前文件夹上方查找的搜索空间(与最大深度相反),因为我没有考虑当前目录中的所有封闭子文件夹

bash find
2个回答
0
投票

不确定我是否真正理解用例,但对于“通用”部分,我认为您可能需要考虑使用

dirname
命令。它基本上返回路径的目录(在本例中为父目录)。 例如,您可以执行
find "$(dirname $PWD)"
... 基本上从父目录中搜索。


0
投票

find: paths must precede expression: ../../'

你的表情

-maxdepth 1
先于路径
../../
,这就是
find
抱怨的原因。

find ../../  -maxdepth 1 -name "${lig}*.png" -exec cp "{}" ${output}  \; 
© www.soinside.com 2019 - 2024. All rights reserved.