List symlinks in specific relative directories
        Posted  
        
            by Clinton Blackmore
        on Server Fault
        
        See other posts from Server Fault
        
            or by Clinton Blackmore
        
        
        
        Published on 2010-03-22T22:11:28Z
        Indexed on 
            2010/03/22
            22:21 UTC
        
        
        Read the original article
        Hit count: 486
        
bash
I have a server that shares out user home folders over the network. Each user has a Cache folder. Sometimes a symlink is used to redirect this folder to the hard drive of whichever machine they are using (and sometimes that doesn't work and they have a broken symlink [which is a matter for another day].)
I'm trying to find out which users have symlinks and which don't. Within the shared folder, to get to the Cache folder you would substitute folders like so:
$GRADE/$USERNAME/Library/Caches
Right now I'm searching to see which users have symlinks and which do not. I've come up with:
cd /path/to/shared/home/folders
sudo find . -name "Caches" -exec ls -ld {} \;
and get results like this:
lrwxr-xr-x@  1 name0  ES_Students   27 Jan 18 11:05 ./CES_Grade_03/name0/Library/Caches -> /tmp/name0/Library/Caches
drwx------  11 name1  ES_Students  374 Dec  8 15:44 ./CES_Grade_03/name1/Library/Caches
lrwxr-xr-x@  1 name2  ES_Students   27 Feb 23 14:27 ./CES_Grade_03/name2/Library/Caches -> /tmp/name2/Library/Caches
drwx------  17 name3  ES_Students  578 Jan 25 11:13 ./CES_Grade_03/name3/Library/Caches
drwx------  12 name4  ES_Students  408 Mar 22 13:09 ./CES_Grade_03/name4/Library/Caches
but it nags at me that there must be a better way. Yes, it is good enough, and a one-off task, but I want to know how to do it right! Surely, I should be able to do something like:
cd /path/to/shared/home/folders
sudo ls -ld **/**/Library/Caches
I'm afraid that I don't know the proper syntax or if there is a recursive folder-replacing wildcard format in bash, and my google-fu failed me.
So, how do I properly formulate the search?
© Server Fault or respective owner