0

I have the following directory structure

[xss]# tree /etc/test
/etc/test
├── challenge
│   └── domain.tld
├── domains
│   └── domain.tld
├── users
│   └── puff
│       └── domain.tld -> /etc/test/domains/domain.tld

And I'm trying to find the parent directory of a soft link matching domain.tld

ex: I want to know in what folder of /etc/test/users is domain.tld found

In this example is puff

So far I got to:

find /etc/test/users -type l -print0 | xargs -0 ls -ld | grep domain.tld
# output lrwxrwxrwx. 1 root root 27 May  3 15:30 /etc/test/users/puff/domain.tld -> /etc/test/domains/domain.tld

LE:

find -L /etc/test/users/ -xtype l | grep domain.tld | sed 's/etc\/test//g'
#output - //users/cb/domain.tld
2
  • 1
    Do you want the link name or the target name to match? May 3, 2021 at 14:43
  • target directory
    – cybernet2u
    May 3, 2021 at 14:55

1 Answer 1

0

With find (GNU findutils) 4.8.0, you can try this way :

dirname $(find /etc/test/users -lname *domain.tld)
7
  • no match :(, can you see my LE, on original post ?
    – cybernet2u
    May 4, 2021 at 8:40
  • @AlexanderBr.Sorry, perhaps i don't understand. I create somewhere a file domain.tld. I create a symbolic link to this file in a subdirectory of somewhere. With my command, I get the directory of the symbolic link from a parent directory of somewhere. With your command from LE, i get a lot of files witch are not symlinks. First you tell about /etc/test/users, after you tell about /etc/xss/users/. Perhaps your question is unclear.
    – ctac_
    May 4, 2021 at 17:35
  • that was my bad :) fixed now
    – cybernet2u
    May 11, 2021 at 13:10
  • with your command, i don't get any results - so i've come up with this version - find /etc/xss/users -lname *domain.tld and I do get /etc/test/users/puff/domain.tld I only want to output puff - as in domain.tld belongs to user puff
    – cybernet2u
    May 11, 2021 at 13:14
  • @AlexanderBr. You are right, i don't know why there is a . in my answer. Update it.
    – ctac_
    May 11, 2021 at 14:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .