Q: recursively removing symlinks
Hi,
I have a number of hard drives on my server that during part of a dedupe process, had many of the original files replaced with symlinks of the type shown here:
lrwxr-xr-x@ 1 russtaylor staff 223 12 Mar 09:26 Cycle-R ICT kit & s:w.xlsx -> /Groups/Cycle-R/Old Data (to sort through)/CJ/Library/Mail/V3/6F89F311-CBFD-462B-92CB-336154CCBE2F/INBOX.mbox/Fin ance and Grants.mbox/55347D5B-6FFF-4324-ADD4-C538EA101DE3/Data/2/Attachments/2893/2/Cycl e-R ICT kit & s:w.xlsx
I now find myself in the dilemma with some 500,000 or more of these things scattered across the server disks, which makes it nigh impossible to find where the real file is buried on the disk due to each file having maybe upwards of 100 alias references to it. Unfortunately the standard Finder tools and similar file management Apps cannot actually identify an Alias file within the Finder, or my task would be easy, thus I must in instance resort to command line, but am not a terminal guru and don't do much coding work these days, so am rather rusty on relevant command syntax and shell scripting, etc.
Ideally I need a simple command line/scripting option along the lines of:
Start
for <directory>
if <filename> is type 'folder'
then open 'folder' and return to Start
else if <filename> is type 'alias/symlink'
then delete 'filename'
else if <filename> is type 'file'
then next <filename>
End
Thus I want to be able to give the function/script the directory /Groups, and have in recursively drill down through all subdirectories, deleting all alias files as it goes, but leaving everything else intact. The end result would be a directory with no aliases or symlinks in it at any level. `I will then be able to recursively remove orphaned empty folders, leaving me with just those directories and subdirectories that have real files in them, which I can then recover and place somewhere useful!
All suggestions gratefully received.
MacBook Pro (15-inch 2.4/2.2 GHz), Mac OS X (10.6.8)
Posted on May 26, 2016 8:12 AM