是否有一种简单的方法来查找文件路径中没有符号链接(symbolic link)的所有文件?
最佳答案
简短:
find myRootDir -type f -print
这可以回答这个问题。
注意不要在指定目录的末尾添加斜杠(不是 myRootDir/
而是 myRootDir
)。
除了真实路径中的真实文件外,这不会打印其他文件。 没有符号链接(symbolic link)文件,也没有符号链接(symbolic link)目录中的文件。
但是...
如果你想确保指定的目录包含符号链接(symbolic link),有一个小 bash 函数可以完成这项工作:
isPurePath() {
if [ -d "$1" ];then
while [ ! -L "$1" ] && [ ${#1} -gt 0 ] ;do
set -- "${1%/*}"
if [ "${1%/*}" == "$1" ] ;then
[ ! -L "$1" ] && return
set -- ''
fi
done
fi
false
}
if isPurePath /usr/share/texmf/dvips/xcolor ;then echo yes; else echo no;fi
yes
if isPurePath /usr/share/texmf/doc/pgf ;then echo yes; else echo no;fi
no
因此,您可以在运行此命令时查找文件路径中没有符号链接(symbolic link)的所有文件:
isPurePath myRootDir && find myRootDir -type f -print
因此,如果打印了某些内容,没有符号链接(symbolic link)部分!
关于linux - 查找文件路径中没有任何部分不是符号链接(symbolic link)的所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13900055/