开发者

Find folders with specific name and no symlink pointing to them

开发者 https://www.devze.com 2022-12-25 18:58 出处:网络
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.

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.

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.

Should be possible with a shellscript or a command, but I have no idea how.

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:

# 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
0

精彩评论

暂无评论...
验证码 换一张
取 消