[英]Find folders with specific name and no symlink pointing to them
I'm trying to write a shell script under linux, which lists all folders (recursively) with a certain name and no symlink pointing to it. 我正在尝试在linux下编写一个shell脚本,它以一定的名称列出所有文件夹(递归),并且没有指向它的符号链接。
For example, I have: 例如,我有:
/home/htdocs/cust1/typo3_src-4.2.11
/home/htdocs/cust2/typo3_src-4.2.12
/home/htdocs/cust3/typo3_src-4.2.12
Now I want to go through all subdirectories of /home/htdocs and find those folders typo3_*, that are not pointed to from somewhere. 现在我想浏览/ home / htdocs的所有子目录,找到那些从某处未指向的文件夹typo3_ *。
Should be possible with a shellscript or a command, but I have no idea how. 应该可以使用shellcript或命令,但我不知道如何。
Thanks for you help 谢谢你的帮助
Stefan 斯特凡
I think none of the common file systems store if there are symlinks pointing to this file in the file node, so you would have to scan all other files to see if it is a symlink to this one. 我认为如果在文件节点中存在指向此文件的符号链接,则不会存储任何公共文件系统,因此您必须扫描所有其他文件以查看它是否是此文件的符号链接。 If you don't limit your depth of search to a certain level, this might take a very long time.
如果您不将搜索深度限制在某个级别,则可能需要很长时间。 If you want to perform that search in
/home/htdocs
, for example, it would work something like this: 例如,如果你想在
/home/htdocs
执行搜索,它会像这样工作:
# find specified folders:
find /home/htdocs -name 'typo3_*' -type d | while read folder; do
# list all symlinks pointing to $folder
find -L /home/htdocs -samefile "$folder"|grep -v "$folder\$"
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.