We have many directories on a server. These directories were created as soft-link and linked it with some NFS share. I would like to list the soft link directories which linked with NFS shares.

we used the commands below to create soft-link directory and link with NFS.

client 1 # ln -s /net/rchserver01/data/share2/ /tmp/
client 1 # ln -s /net/rchserver01/data/share1/ /var/
client 1 # ll /tmp/
lrwxrwxrwx 1 root     root  27 Sep 13 11:38 share2 -> /net/rchserver01/data/share2/
client 1 # ll /var/
lrwxrwxrwx 1 root     root  27 Sep 13 11:38 share2 -> /net/rchserver01/data/share1/
  • Are all the NFS shares under /net? Just wondering what assumptions we can make. – Jeff Schaller Sep 13 '18 at 17:23
  • Yes, using mount command I can see the NFS servers. But I need to know the softlink directories where these NFS mounted. – Pandu Sep 13 '18 at 17:25

Given the sample input:

find /tmp -lname '/net/*'

More generally, tell find to explore every local filesystem, but to stay on each filesystem:

find $(lsblk --list --noheadings --output MOUNTPOINT | grep /) -xdev -lname '/net/*'

Even more generally, ask find to search the local filesystems, as above, but build up a list of possible NFS targets:

readarray -t nfsmounts < <(awk '$3 ~ /^nfs/ { print $2 }' < /proc/mounts)
excludes+=(" -lname ${nfsmounts[0]}")
for((i=1;i < ${#nfsmounts[@]}; i++))
  excludes+=( " -o -lname '${nfsmounts[i]}/*'")
find $(lsblk --list --noheadings --output MOUNTPOINT | grep /) -xdev ${excludes[@]}

Another alternative for the starting list of filesystems: parse /proc/filesystems for filesystem types that are not nodev:

find $( for type in $(awk '$1 != "nodev"' /proc/filesystems); do mount -l -t "$type" | awk '{print $3}'; done ) \
  -xdev -lname '/net/*'
  • Thanks a lot !! It worked. But I need to run find command for all filesystems to find the softlink dirs. Since I would not know where my softlink dir exists. – Pandu Sep 13 '18 at 17:33
  • Run the find with all your local filesystems, and add -xdev; looking to see if we have a good "local filesystems" answer here... stole one of my own – Jeff Schaller Sep 13 '18 at 17:35
  • @JeffSchaller Maybe find / -type nfs -prune -lname '/net/*' This should not descend into any NFS file systems. – doneal24 Sep 13 '18 at 17:48
  • Aye, @Doug, but there's also tmpfs and sysfs and devpts and autofs and ... – Jeff Schaller Sep 13 '18 at 17:53
  • Maybe something more along the lines of mount -l -t (each of -- awk '$1 != "nodev"' /proc/filesystems) – Jeff Schaller Sep 13 '18 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.