简体   繁体   English

查找具有特定名称的文件夹,并且没有指向它们的符号链接

[英]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.

相关问题 查找特定文件夹,然后在其中搜索特定文件以查找单词 - Find specific folders then search specific files inside them for a word 以特定名称递归查找目录,然后清除它们 - Recursively find directories by a specific name and then clear them Linux:查找所有具有特定名称的文件夹,将其删除,然后将一个文件夹复制到这些文件夹的父目录中 - Linux: Find all folders with a particular name, remove them and have a folder copied into the parent directory of those folders 在SSH中按名称查找和替换文件或文件夹 - Find And Replace Files Or Folders By Name In SSH Linux bash:查找包含特定文本的文件夹 - Linux bash: find folders containing specific text 厕所与查找。 如果文件夹名称中有空格则错误 - wc with find. error if space in folders name 在find命令中的路径中使用带有〜的符号链接 - Using a symlink with ~ in path in a find command Bash-在目录及其目录中找到几个特定的​​文件夹,然后重命名这些特定的文件夹 - Bash - Find several specific folders in a directory and its sbdirectories and rename these specific folders 按名称查找文件夹并将其子文件夹的权限递归设置为755 - Find a folder by name and recursively set it's childrens folders permission to 755 Linux根据名称长度查找文件和文件夹,但输出完整路径 - Linux find files and folders based on name length but output full path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM