linux - 查找文件路径中没有任何部分不是符号链接(symbolic link)的所有文件

标签 linux shell symlink

是否有一种简单的方法来查找文件路径中没有符号链接(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/

相关文章:

linux - 从 udev 规则和 shell 脚本自动挂载 USB 驱动器

bash - mpc 当前歌曲 bash 脚本故障安全

linux - svn:此平台不支持符号链接(symbolic link) - Windows 8.1

Windows如何创建目录符号链接(symbolic link)

linux - Tar 将相对符号链接(symbolic link)更改为绝对符号链接(symbolic link)

android - Android 终端中的 Wget

linux - 了解 RT 调度类 linux 的 dequeue_rt_stack()

c++ - 如何使用 QProcess 通过 Ping 检测 "Network is Unreachable"?

asp.net-mvc - 在单声道下从 asp.net mvc 应用程序安全地运行 linux 命令行应用程序

linux - Rhapsody 可以配置为使用外部源代码编辑器吗?