我想列出目录中未被同一目录中的任何符号链接引用的所有文件。因此,如果一个文件被另一个目录中的符号链接引用并且仍然会被列出。我尝试使用find
,readlink
和uniq
,但它没有按照我想要的方式进行操作
\(
find -maxdepth 1 -type l -exec readlink {} ';' ;
find -maxdepth 1 -type f
\) > "output"
uniq -u "output"
我是Unix / Linux的新手。提前致谢
答案 0 :(得分:1)
试试这个:
# Create a temp file containing the names of all the symlinks
tmp=$(mktemp)
find -maxdepth 1 -type l > $tmp
# List all the regular files, and remove (grep -vF) the symlinks
find -maxdepth 1 -type f | grep -vF -f $tmp
# Clean up
rm -f $tmp
-v
的{{1}}选项使其反转其匹配逻辑。换句话说,“给我所有不匹配模式的项目。” grep
选项告诉-F
该模式由固定字符串列表组成,而不是正则表达式。您不希望grep
尝试将文件名中的任何特殊字符解释为正则表达式符号。最后,grep
的{{1}}选项告诉它从文件而不是从命令行读取此固定字符串列表。