Shell 查找:警告:Unix文件名通常不';不要包含斜线

Shell 查找:警告:Unix文件名通常不';不要包含斜线,shell,unix,Shell,Unix,我写了一个shell脚本。我有个问题。 我运行脚本时出错 我的错误如下: find: warning: Unix filenames usually don't contain slashes (though pathnames do). That means that '-name 'computer/'' will probably evaluate to false all the time on this system. You might find the '-wholename' t

我写了一个shell脚本。我有个问题。 我运行脚本时出错 我的错误如下:

find: warning: Unix filenames usually don't contain slashes (though pathnames do).
That means that '-name 'computer/'' will probably evaluate to false all the time on this system.
You might find the '-wholename' test more useful, or perhaps '-samefile'.  
Alternatively, if you are using GNU grep, you could use 'find ... -print0 | grep -FzZ `computer/''.
/behome/computer/.mozilla
/behome/computer/.mozilla/extensions
/behome/computer/.mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}
...

由于您不需要遍历树,而只需要查看这些文件夹,因此不需要查找:

check_input_directories()
{
    if [ -d "${folder1}" ] && [ -d "${folder2}" ] ; then
        for i in ~/${folder1}/* ; do
            if [ -f ~/${folder2}/${i##*/} ] ; then
                echo ${i##*/}
            fi
        done
    fi
}

我看到一个警告,但没有错误…您是否错过了预期的结果?得到了你意想不到的结果?考虑到您显示的输出中没有一个包含
folder1
folder2
,我认为您实际上也没有运行
/scriptname-d folder1 folder2
。这个脚本应该做什么?另外,使用
find
类似于:
find$dir1-printf“%f\n”
正在目录
$dir1
中查找文件;它没有查找名为
$dir1
的目录。这就是您想要做的吗?问题是您正在传递一个到
find
-name
参数的完整路径。您希望此脚本具体执行什么操作?如果您只是想查找文件是否在第二个目录中,那么可以将
find
设置为:
find$dir2-name“${i##*/}”-print
这些只是一级(平面)目录还是整个树结构?如果是平面,则不需要
查找
。另一方面,您的
if[[[-d”${folder1}“${folder2}”]
看起来像是语法错误,因为
-d
只接受一个参数。我需要两个参数,因为比较(查找具有相同文件的文件)将在两个不同的文件夹中完成。@user2874061这是不正确的<代码>-d folder1 folder2语法无效。如果你想检查多个文件夹,你必须像我所展示的那样分别检查。我使用了“&&”,即和。@user2874061我测试了我发布的脚本的最新编辑,它对我有效。