How can I locate all Mac OS X 'alias' files and find their target files (despite broken links)?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite
1












I just figured out that I'm dealing with symlinks rather than aliases per se. (For some reason, they show up as aliases in finder.)



I have a ton of unexplained SYMLINKS on my HDD.
And unfortunately the SYMLINKS don't work -- i.e., clicking on it doesn't get me to the file.



So now I would like to find all SYMLINKS on my HDD.
Then for each one, search for the file that it once linked to, presumably on the same HDD.
Then copy that file to the same subdirectory as the SYMLINK.



So I have, roughly speaking,



FIND all files (in Directory) type=SYMLINK. FOR each one, DO ..
FIND referentFile (somewhere on the HDD)
cp referentFile to (Subdirectory that contains the alias).
DONE.


Many Thanks.
PS -- I'm really considering going back to strictly Linux over this. The simpler the setup, the less likely a data disaster - lol.







share|improve this question






















  • Thank you all for informative suggestions. I'm adding edit to OP, cuz I just figured out that I'm dealing with symlinks rather than aliases per se. (For some reason, they show up as aliases in finder.) Sorry if I wasted your time with wrong question.
    – ericlindellnyc
    Dec 16 '17 at 18:10










  • I'm not sure how you'd figure out what file a symlink used to point to -- a symlink's target is just a unix path, and if there's no file at that path... what criteria can we use to find the original file?
    – Gordon Davisson
    Dec 16 '17 at 22:38














up vote
3
down vote

favorite
1












I just figured out that I'm dealing with symlinks rather than aliases per se. (For some reason, they show up as aliases in finder.)



I have a ton of unexplained SYMLINKS on my HDD.
And unfortunately the SYMLINKS don't work -- i.e., clicking on it doesn't get me to the file.



So now I would like to find all SYMLINKS on my HDD.
Then for each one, search for the file that it once linked to, presumably on the same HDD.
Then copy that file to the same subdirectory as the SYMLINK.



So I have, roughly speaking,



FIND all files (in Directory) type=SYMLINK. FOR each one, DO ..
FIND referentFile (somewhere on the HDD)
cp referentFile to (Subdirectory that contains the alias).
DONE.


Many Thanks.
PS -- I'm really considering going back to strictly Linux over this. The simpler the setup, the less likely a data disaster - lol.







share|improve this question






















  • Thank you all for informative suggestions. I'm adding edit to OP, cuz I just figured out that I'm dealing with symlinks rather than aliases per se. (For some reason, they show up as aliases in finder.) Sorry if I wasted your time with wrong question.
    – ericlindellnyc
    Dec 16 '17 at 18:10










  • I'm not sure how you'd figure out what file a symlink used to point to -- a symlink's target is just a unix path, and if there's no file at that path... what criteria can we use to find the original file?
    – Gordon Davisson
    Dec 16 '17 at 22:38












up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





I just figured out that I'm dealing with symlinks rather than aliases per se. (For some reason, they show up as aliases in finder.)



I have a ton of unexplained SYMLINKS on my HDD.
And unfortunately the SYMLINKS don't work -- i.e., clicking on it doesn't get me to the file.



So now I would like to find all SYMLINKS on my HDD.
Then for each one, search for the file that it once linked to, presumably on the same HDD.
Then copy that file to the same subdirectory as the SYMLINK.



So I have, roughly speaking,



FIND all files (in Directory) type=SYMLINK. FOR each one, DO ..
FIND referentFile (somewhere on the HDD)
cp referentFile to (Subdirectory that contains the alias).
DONE.


Many Thanks.
PS -- I'm really considering going back to strictly Linux over this. The simpler the setup, the less likely a data disaster - lol.







share|improve this question














I just figured out that I'm dealing with symlinks rather than aliases per se. (For some reason, they show up as aliases in finder.)



I have a ton of unexplained SYMLINKS on my HDD.
And unfortunately the SYMLINKS don't work -- i.e., clicking on it doesn't get me to the file.



So now I would like to find all SYMLINKS on my HDD.
Then for each one, search for the file that it once linked to, presumably on the same HDD.
Then copy that file to the same subdirectory as the SYMLINK.



So I have, roughly speaking,



FIND all files (in Directory) type=SYMLINK. FOR each one, DO ..
FIND referentFile (somewhere on the HDD)
cp referentFile to (Subdirectory that contains the alias).
DONE.


Many Thanks.
PS -- I'm really considering going back to strictly Linux over this. The simpler the setup, the less likely a data disaster - lol.









share|improve this question













share|improve this question




share|improve this question








edited Dec 16 '17 at 18:14

























asked Dec 7 '17 at 21:56









ericlindellnyc

163




163











  • Thank you all for informative suggestions. I'm adding edit to OP, cuz I just figured out that I'm dealing with symlinks rather than aliases per se. (For some reason, they show up as aliases in finder.) Sorry if I wasted your time with wrong question.
    – ericlindellnyc
    Dec 16 '17 at 18:10










  • I'm not sure how you'd figure out what file a symlink used to point to -- a symlink's target is just a unix path, and if there's no file at that path... what criteria can we use to find the original file?
    – Gordon Davisson
    Dec 16 '17 at 22:38
















  • Thank you all for informative suggestions. I'm adding edit to OP, cuz I just figured out that I'm dealing with symlinks rather than aliases per se. (For some reason, they show up as aliases in finder.) Sorry if I wasted your time with wrong question.
    – ericlindellnyc
    Dec 16 '17 at 18:10










  • I'm not sure how you'd figure out what file a symlink used to point to -- a symlink's target is just a unix path, and if there's no file at that path... what criteria can we use to find the original file?
    – Gordon Davisson
    Dec 16 '17 at 22:38















Thank you all for informative suggestions. I'm adding edit to OP, cuz I just figured out that I'm dealing with symlinks rather than aliases per se. (For some reason, they show up as aliases in finder.) Sorry if I wasted your time with wrong question.
– ericlindellnyc
Dec 16 '17 at 18:10




Thank you all for informative suggestions. I'm adding edit to OP, cuz I just figured out that I'm dealing with symlinks rather than aliases per se. (For some reason, they show up as aliases in finder.) Sorry if I wasted your time with wrong question.
– ericlindellnyc
Dec 16 '17 at 18:10












I'm not sure how you'd figure out what file a symlink used to point to -- a symlink's target is just a unix path, and if there's no file at that path... what criteria can we use to find the original file?
– Gordon Davisson
Dec 16 '17 at 22:38




I'm not sure how you'd figure out what file a symlink used to point to -- a symlink's target is just a unix path, and if there's no file at that path... what criteria can we use to find the original file?
– Gordon Davisson
Dec 16 '17 at 22:38










2 Answers
2






active

oldest

votes

















up vote
0
down vote













The first part of this question has an answer on AskDifferent:



  • How to find all the aliases within a given file system?

Here is the command to find aliases:



mdfind kMDItemKind="Alias"


In general you can use the mdfind (MetaData Find) command to (very) quickly search for files. From the man-pages:




The mdfind command consults the central metadata store and returns a list of files that match the given metadata query. The query can be a string or a query expression.




So I wouldn't give up on OSX just yet. In fact, mdfind is one of the things I miss most about OSX when I'm on Linux.



Unfortunately the second part of this question was surprisingly more difficult to resolve. I found a few relevant StackExchange posts:



  • How to query target of all Finder aliases?


  • OS X terminal command to resolve path of an alias


  • How do I fix failed aliases?


  • Reading Alias files


These led me to several potential solutions.



My favorite came from the blog post Make Terminal Follow Aliases Like Symlinks. It referenced a small open-source C program called getTrueName.c. Here is the source code:



// getTrueName.c
//
// DESCRIPTION
// Resolve HFS and HFS+ aliased files (and soft links), and return the
// name of the "Original" or actual file. Directories have a "/"
// appended. The error number returned is 255 on error, 0 if the file
// was an alias, or 1 if the argument given was not an alias
//
// BUILD INSTRUCTIONS
// gcc-3.3 -o getTrueName -framework Carbon getTrueName.c
//
// Note: gcc version 4 reports the following warning
// warning: pointer targets in passing argument 1 of 'FSPathMakeRef'
// differ in signedness
//
// COPYRIGHT AND LICENSE
// Copyright 2005 by Thos Davis. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307 USA


#include <Carbon/Carbon.h>
#define MAX_PATH_SIZE 1024
#define CHECK(rc,check_value) if ((check_value) != noErr) exit((rc))

int main ( int argc, char * argv )

FSRef fsRef;
Boolean targetIsFolder;
Boolean wasAliased;
UInt8 targetPath[MAX_PATH_SIZE+1];
char * marker;

// if there are no arguments, go away
if (argc < 2 ) exit(255);

CHECK( 255,
FSPathMakeRef( argv[1], &fsRef, NULL ));

CHECK( 1,
FSResolveAliasFile( &fsRef, TRUE, &targetIsFolder, &wasAliased));

CHECK( 255,
FSRefMakePath( &fsRef, targetPath, MAX_PATH_SIZE));

marker = targetIsFolder ? "/" : "" ;
printf( "%s%sn", targetPath, marker );

exit( 1 - wasAliased );



I downloaded this source code and compiled using the following command:



gcc -o getTrueName -framework Carbon getTrueName.c


Of course I wanted to test it out. In order to avoid leaving the terminal I created an alias using the following commands:



user@host:~$ FULL_PATH_TO_TARGET_FILE=/tmp/alias-target

user@host:~$ echo "testing" > "$FULL_PATH_TO_TARGET_FILE"

user@host:~$ osascript
-e 'tell application "Finder"'
-e "make new alias to file (posix file "$FULL_PATH_TO_TARGET_FILE") at desktop"
-e 'end tell'

alias file alias-target of folder Desktop of folder user of folder Users of disk MacHD


Then I verified the Alias using the getTrueName program:



user@host:~$ ./getTrueName ~/Desktop/alias-target

/tmp/alias-target


Victory!



The blog post Stupid Mac OS X Tricks: Resolving Aliases also looks like it might have a solution. It contained the following Perl script:



#!/usr/local/bin/perl
use Mac::Errors;
use Mac::Files;
use Mac::Resources;

my $path = '/Users/pudge/Desktop/some alias';
my $res = FSpOpenResFile($path, 0) or die $Mac::Errors::MacError;
# get resource by index; get first "alis" resource
my $alis = GetIndResource('alis', 1) or die $Mac::Errors::MacError;
my $link = ResolveAlias($alis);
print $link;


I didn't have the required libraries and I didn't feel like installing a bunch of stuff, so I gave up on this one.



I also found the mac_alias, which seemed promising. I spent 5 or 10 minutes messing around with it, but wasn't able to figure out how to resolve an alias target.






share|improve this answer






















  • Thanks for the answer. This works great. I'd also like to know how to find the original referent file, given that the alias no longer points to it. There's tons of these broken alias links that need to be resolved. I'd like to use one script that finds all aliases and, for each one, finds its referent. Is that possible? Thanks.
    – ericlindellnyc
    Dec 13 '17 at 17:07










  • @ericlindellnyc Ok, I think I found what you're looking for. I included links to all of my references - hopefully it's not too disorganized. Let me know what you think.
    – igal
    Dec 14 '17 at 2:47

















up vote
0
down vote













I might have figured out how to locate referent files for symlinks that are broken.



[Btw, I'm the OP -- couldn't find original loginfo, so I signed up anew.]



Use a duplicate file finder like dupeGuru. Set it to
o Search entire directory/drives containing symlinks and referents.
o Mix files of different types.
o Inexact matches are okay (i.e., certainty-level around 80%).
o Match filename only (not content or entire directory).



This will turn up many false positives, but it will include symlinks and their referents (broken or intact).






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409589%2fhow-can-i-locate-all-mac-os-x-alias-files-and-find-their-target-files-despite%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    The first part of this question has an answer on AskDifferent:



    • How to find all the aliases within a given file system?

    Here is the command to find aliases:



    mdfind kMDItemKind="Alias"


    In general you can use the mdfind (MetaData Find) command to (very) quickly search for files. From the man-pages:




    The mdfind command consults the central metadata store and returns a list of files that match the given metadata query. The query can be a string or a query expression.




    So I wouldn't give up on OSX just yet. In fact, mdfind is one of the things I miss most about OSX when I'm on Linux.



    Unfortunately the second part of this question was surprisingly more difficult to resolve. I found a few relevant StackExchange posts:



    • How to query target of all Finder aliases?


    • OS X terminal command to resolve path of an alias


    • How do I fix failed aliases?


    • Reading Alias files


    These led me to several potential solutions.



    My favorite came from the blog post Make Terminal Follow Aliases Like Symlinks. It referenced a small open-source C program called getTrueName.c. Here is the source code:



    // getTrueName.c
    //
    // DESCRIPTION
    // Resolve HFS and HFS+ aliased files (and soft links), and return the
    // name of the "Original" or actual file. Directories have a "/"
    // appended. The error number returned is 255 on error, 0 if the file
    // was an alias, or 1 if the argument given was not an alias
    //
    // BUILD INSTRUCTIONS
    // gcc-3.3 -o getTrueName -framework Carbon getTrueName.c
    //
    // Note: gcc version 4 reports the following warning
    // warning: pointer targets in passing argument 1 of 'FSPathMakeRef'
    // differ in signedness
    //
    // COPYRIGHT AND LICENSE
    // Copyright 2005 by Thos Davis. All rights reserved.
    // This program is free software; you can redistribute it and/or
    // modify it under the terms of the GNU General Public License as
    // published by the Free Software Foundation; either version 2 of the
    // License, or (at your option) any later version.
    //
    // This program is distributed in the hope that it will be useful, but
    // WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    // General Public License for more details.
    //
    // You should have received a copy of the GNU General Public
    // License along with this program; if not, write to the Free
    // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
    // MA 02111-1307 USA


    #include <Carbon/Carbon.h>
    #define MAX_PATH_SIZE 1024
    #define CHECK(rc,check_value) if ((check_value) != noErr) exit((rc))

    int main ( int argc, char * argv )

    FSRef fsRef;
    Boolean targetIsFolder;
    Boolean wasAliased;
    UInt8 targetPath[MAX_PATH_SIZE+1];
    char * marker;

    // if there are no arguments, go away
    if (argc < 2 ) exit(255);

    CHECK( 255,
    FSPathMakeRef( argv[1], &fsRef, NULL ));

    CHECK( 1,
    FSResolveAliasFile( &fsRef, TRUE, &targetIsFolder, &wasAliased));

    CHECK( 255,
    FSRefMakePath( &fsRef, targetPath, MAX_PATH_SIZE));

    marker = targetIsFolder ? "/" : "" ;
    printf( "%s%sn", targetPath, marker );

    exit( 1 - wasAliased );



    I downloaded this source code and compiled using the following command:



    gcc -o getTrueName -framework Carbon getTrueName.c


    Of course I wanted to test it out. In order to avoid leaving the terminal I created an alias using the following commands:



    user@host:~$ FULL_PATH_TO_TARGET_FILE=/tmp/alias-target

    user@host:~$ echo "testing" > "$FULL_PATH_TO_TARGET_FILE"

    user@host:~$ osascript
    -e 'tell application "Finder"'
    -e "make new alias to file (posix file "$FULL_PATH_TO_TARGET_FILE") at desktop"
    -e 'end tell'

    alias file alias-target of folder Desktop of folder user of folder Users of disk MacHD


    Then I verified the Alias using the getTrueName program:



    user@host:~$ ./getTrueName ~/Desktop/alias-target

    /tmp/alias-target


    Victory!



    The blog post Stupid Mac OS X Tricks: Resolving Aliases also looks like it might have a solution. It contained the following Perl script:



    #!/usr/local/bin/perl
    use Mac::Errors;
    use Mac::Files;
    use Mac::Resources;

    my $path = '/Users/pudge/Desktop/some alias';
    my $res = FSpOpenResFile($path, 0) or die $Mac::Errors::MacError;
    # get resource by index; get first "alis" resource
    my $alis = GetIndResource('alis', 1) or die $Mac::Errors::MacError;
    my $link = ResolveAlias($alis);
    print $link;


    I didn't have the required libraries and I didn't feel like installing a bunch of stuff, so I gave up on this one.



    I also found the mac_alias, which seemed promising. I spent 5 or 10 minutes messing around with it, but wasn't able to figure out how to resolve an alias target.






    share|improve this answer






















    • Thanks for the answer. This works great. I'd also like to know how to find the original referent file, given that the alias no longer points to it. There's tons of these broken alias links that need to be resolved. I'd like to use one script that finds all aliases and, for each one, finds its referent. Is that possible? Thanks.
      – ericlindellnyc
      Dec 13 '17 at 17:07










    • @ericlindellnyc Ok, I think I found what you're looking for. I included links to all of my references - hopefully it's not too disorganized. Let me know what you think.
      – igal
      Dec 14 '17 at 2:47














    up vote
    0
    down vote













    The first part of this question has an answer on AskDifferent:



    • How to find all the aliases within a given file system?

    Here is the command to find aliases:



    mdfind kMDItemKind="Alias"


    In general you can use the mdfind (MetaData Find) command to (very) quickly search for files. From the man-pages:




    The mdfind command consults the central metadata store and returns a list of files that match the given metadata query. The query can be a string or a query expression.




    So I wouldn't give up on OSX just yet. In fact, mdfind is one of the things I miss most about OSX when I'm on Linux.



    Unfortunately the second part of this question was surprisingly more difficult to resolve. I found a few relevant StackExchange posts:



    • How to query target of all Finder aliases?


    • OS X terminal command to resolve path of an alias


    • How do I fix failed aliases?


    • Reading Alias files


    These led me to several potential solutions.



    My favorite came from the blog post Make Terminal Follow Aliases Like Symlinks. It referenced a small open-source C program called getTrueName.c. Here is the source code:



    // getTrueName.c
    //
    // DESCRIPTION
    // Resolve HFS and HFS+ aliased files (and soft links), and return the
    // name of the "Original" or actual file. Directories have a "/"
    // appended. The error number returned is 255 on error, 0 if the file
    // was an alias, or 1 if the argument given was not an alias
    //
    // BUILD INSTRUCTIONS
    // gcc-3.3 -o getTrueName -framework Carbon getTrueName.c
    //
    // Note: gcc version 4 reports the following warning
    // warning: pointer targets in passing argument 1 of 'FSPathMakeRef'
    // differ in signedness
    //
    // COPYRIGHT AND LICENSE
    // Copyright 2005 by Thos Davis. All rights reserved.
    // This program is free software; you can redistribute it and/or
    // modify it under the terms of the GNU General Public License as
    // published by the Free Software Foundation; either version 2 of the
    // License, or (at your option) any later version.
    //
    // This program is distributed in the hope that it will be useful, but
    // WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    // General Public License for more details.
    //
    // You should have received a copy of the GNU General Public
    // License along with this program; if not, write to the Free
    // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
    // MA 02111-1307 USA


    #include <Carbon/Carbon.h>
    #define MAX_PATH_SIZE 1024
    #define CHECK(rc,check_value) if ((check_value) != noErr) exit((rc))

    int main ( int argc, char * argv )

    FSRef fsRef;
    Boolean targetIsFolder;
    Boolean wasAliased;
    UInt8 targetPath[MAX_PATH_SIZE+1];
    char * marker;

    // if there are no arguments, go away
    if (argc < 2 ) exit(255);

    CHECK( 255,
    FSPathMakeRef( argv[1], &fsRef, NULL ));

    CHECK( 1,
    FSResolveAliasFile( &fsRef, TRUE, &targetIsFolder, &wasAliased));

    CHECK( 255,
    FSRefMakePath( &fsRef, targetPath, MAX_PATH_SIZE));

    marker = targetIsFolder ? "/" : "" ;
    printf( "%s%sn", targetPath, marker );

    exit( 1 - wasAliased );



    I downloaded this source code and compiled using the following command:



    gcc -o getTrueName -framework Carbon getTrueName.c


    Of course I wanted to test it out. In order to avoid leaving the terminal I created an alias using the following commands:



    user@host:~$ FULL_PATH_TO_TARGET_FILE=/tmp/alias-target

    user@host:~$ echo "testing" > "$FULL_PATH_TO_TARGET_FILE"

    user@host:~$ osascript
    -e 'tell application "Finder"'
    -e "make new alias to file (posix file "$FULL_PATH_TO_TARGET_FILE") at desktop"
    -e 'end tell'

    alias file alias-target of folder Desktop of folder user of folder Users of disk MacHD


    Then I verified the Alias using the getTrueName program:



    user@host:~$ ./getTrueName ~/Desktop/alias-target

    /tmp/alias-target


    Victory!



    The blog post Stupid Mac OS X Tricks: Resolving Aliases also looks like it might have a solution. It contained the following Perl script:



    #!/usr/local/bin/perl
    use Mac::Errors;
    use Mac::Files;
    use Mac::Resources;

    my $path = '/Users/pudge/Desktop/some alias';
    my $res = FSpOpenResFile($path, 0) or die $Mac::Errors::MacError;
    # get resource by index; get first "alis" resource
    my $alis = GetIndResource('alis', 1) or die $Mac::Errors::MacError;
    my $link = ResolveAlias($alis);
    print $link;


    I didn't have the required libraries and I didn't feel like installing a bunch of stuff, so I gave up on this one.



    I also found the mac_alias, which seemed promising. I spent 5 or 10 minutes messing around with it, but wasn't able to figure out how to resolve an alias target.






    share|improve this answer






















    • Thanks for the answer. This works great. I'd also like to know how to find the original referent file, given that the alias no longer points to it. There's tons of these broken alias links that need to be resolved. I'd like to use one script that finds all aliases and, for each one, finds its referent. Is that possible? Thanks.
      – ericlindellnyc
      Dec 13 '17 at 17:07










    • @ericlindellnyc Ok, I think I found what you're looking for. I included links to all of my references - hopefully it's not too disorganized. Let me know what you think.
      – igal
      Dec 14 '17 at 2:47












    up vote
    0
    down vote










    up vote
    0
    down vote









    The first part of this question has an answer on AskDifferent:



    • How to find all the aliases within a given file system?

    Here is the command to find aliases:



    mdfind kMDItemKind="Alias"


    In general you can use the mdfind (MetaData Find) command to (very) quickly search for files. From the man-pages:




    The mdfind command consults the central metadata store and returns a list of files that match the given metadata query. The query can be a string or a query expression.




    So I wouldn't give up on OSX just yet. In fact, mdfind is one of the things I miss most about OSX when I'm on Linux.



    Unfortunately the second part of this question was surprisingly more difficult to resolve. I found a few relevant StackExchange posts:



    • How to query target of all Finder aliases?


    • OS X terminal command to resolve path of an alias


    • How do I fix failed aliases?


    • Reading Alias files


    These led me to several potential solutions.



    My favorite came from the blog post Make Terminal Follow Aliases Like Symlinks. It referenced a small open-source C program called getTrueName.c. Here is the source code:



    // getTrueName.c
    //
    // DESCRIPTION
    // Resolve HFS and HFS+ aliased files (and soft links), and return the
    // name of the "Original" or actual file. Directories have a "/"
    // appended. The error number returned is 255 on error, 0 if the file
    // was an alias, or 1 if the argument given was not an alias
    //
    // BUILD INSTRUCTIONS
    // gcc-3.3 -o getTrueName -framework Carbon getTrueName.c
    //
    // Note: gcc version 4 reports the following warning
    // warning: pointer targets in passing argument 1 of 'FSPathMakeRef'
    // differ in signedness
    //
    // COPYRIGHT AND LICENSE
    // Copyright 2005 by Thos Davis. All rights reserved.
    // This program is free software; you can redistribute it and/or
    // modify it under the terms of the GNU General Public License as
    // published by the Free Software Foundation; either version 2 of the
    // License, or (at your option) any later version.
    //
    // This program is distributed in the hope that it will be useful, but
    // WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    // General Public License for more details.
    //
    // You should have received a copy of the GNU General Public
    // License along with this program; if not, write to the Free
    // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
    // MA 02111-1307 USA


    #include <Carbon/Carbon.h>
    #define MAX_PATH_SIZE 1024
    #define CHECK(rc,check_value) if ((check_value) != noErr) exit((rc))

    int main ( int argc, char * argv )

    FSRef fsRef;
    Boolean targetIsFolder;
    Boolean wasAliased;
    UInt8 targetPath[MAX_PATH_SIZE+1];
    char * marker;

    // if there are no arguments, go away
    if (argc < 2 ) exit(255);

    CHECK( 255,
    FSPathMakeRef( argv[1], &fsRef, NULL ));

    CHECK( 1,
    FSResolveAliasFile( &fsRef, TRUE, &targetIsFolder, &wasAliased));

    CHECK( 255,
    FSRefMakePath( &fsRef, targetPath, MAX_PATH_SIZE));

    marker = targetIsFolder ? "/" : "" ;
    printf( "%s%sn", targetPath, marker );

    exit( 1 - wasAliased );



    I downloaded this source code and compiled using the following command:



    gcc -o getTrueName -framework Carbon getTrueName.c


    Of course I wanted to test it out. In order to avoid leaving the terminal I created an alias using the following commands:



    user@host:~$ FULL_PATH_TO_TARGET_FILE=/tmp/alias-target

    user@host:~$ echo "testing" > "$FULL_PATH_TO_TARGET_FILE"

    user@host:~$ osascript
    -e 'tell application "Finder"'
    -e "make new alias to file (posix file "$FULL_PATH_TO_TARGET_FILE") at desktop"
    -e 'end tell'

    alias file alias-target of folder Desktop of folder user of folder Users of disk MacHD


    Then I verified the Alias using the getTrueName program:



    user@host:~$ ./getTrueName ~/Desktop/alias-target

    /tmp/alias-target


    Victory!



    The blog post Stupid Mac OS X Tricks: Resolving Aliases also looks like it might have a solution. It contained the following Perl script:



    #!/usr/local/bin/perl
    use Mac::Errors;
    use Mac::Files;
    use Mac::Resources;

    my $path = '/Users/pudge/Desktop/some alias';
    my $res = FSpOpenResFile($path, 0) or die $Mac::Errors::MacError;
    # get resource by index; get first "alis" resource
    my $alis = GetIndResource('alis', 1) or die $Mac::Errors::MacError;
    my $link = ResolveAlias($alis);
    print $link;


    I didn't have the required libraries and I didn't feel like installing a bunch of stuff, so I gave up on this one.



    I also found the mac_alias, which seemed promising. I spent 5 or 10 minutes messing around with it, but wasn't able to figure out how to resolve an alias target.






    share|improve this answer














    The first part of this question has an answer on AskDifferent:



    • How to find all the aliases within a given file system?

    Here is the command to find aliases:



    mdfind kMDItemKind="Alias"


    In general you can use the mdfind (MetaData Find) command to (very) quickly search for files. From the man-pages:




    The mdfind command consults the central metadata store and returns a list of files that match the given metadata query. The query can be a string or a query expression.




    So I wouldn't give up on OSX just yet. In fact, mdfind is one of the things I miss most about OSX when I'm on Linux.



    Unfortunately the second part of this question was surprisingly more difficult to resolve. I found a few relevant StackExchange posts:



    • How to query target of all Finder aliases?


    • OS X terminal command to resolve path of an alias


    • How do I fix failed aliases?


    • Reading Alias files


    These led me to several potential solutions.



    My favorite came from the blog post Make Terminal Follow Aliases Like Symlinks. It referenced a small open-source C program called getTrueName.c. Here is the source code:



    // getTrueName.c
    //
    // DESCRIPTION
    // Resolve HFS and HFS+ aliased files (and soft links), and return the
    // name of the "Original" or actual file. Directories have a "/"
    // appended. The error number returned is 255 on error, 0 if the file
    // was an alias, or 1 if the argument given was not an alias
    //
    // BUILD INSTRUCTIONS
    // gcc-3.3 -o getTrueName -framework Carbon getTrueName.c
    //
    // Note: gcc version 4 reports the following warning
    // warning: pointer targets in passing argument 1 of 'FSPathMakeRef'
    // differ in signedness
    //
    // COPYRIGHT AND LICENSE
    // Copyright 2005 by Thos Davis. All rights reserved.
    // This program is free software; you can redistribute it and/or
    // modify it under the terms of the GNU General Public License as
    // published by the Free Software Foundation; either version 2 of the
    // License, or (at your option) any later version.
    //
    // This program is distributed in the hope that it will be useful, but
    // WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    // General Public License for more details.
    //
    // You should have received a copy of the GNU General Public
    // License along with this program; if not, write to the Free
    // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
    // MA 02111-1307 USA


    #include <Carbon/Carbon.h>
    #define MAX_PATH_SIZE 1024
    #define CHECK(rc,check_value) if ((check_value) != noErr) exit((rc))

    int main ( int argc, char * argv )

    FSRef fsRef;
    Boolean targetIsFolder;
    Boolean wasAliased;
    UInt8 targetPath[MAX_PATH_SIZE+1];
    char * marker;

    // if there are no arguments, go away
    if (argc < 2 ) exit(255);

    CHECK( 255,
    FSPathMakeRef( argv[1], &fsRef, NULL ));

    CHECK( 1,
    FSResolveAliasFile( &fsRef, TRUE, &targetIsFolder, &wasAliased));

    CHECK( 255,
    FSRefMakePath( &fsRef, targetPath, MAX_PATH_SIZE));

    marker = targetIsFolder ? "/" : "" ;
    printf( "%s%sn", targetPath, marker );

    exit( 1 - wasAliased );



    I downloaded this source code and compiled using the following command:



    gcc -o getTrueName -framework Carbon getTrueName.c


    Of course I wanted to test it out. In order to avoid leaving the terminal I created an alias using the following commands:



    user@host:~$ FULL_PATH_TO_TARGET_FILE=/tmp/alias-target

    user@host:~$ echo "testing" > "$FULL_PATH_TO_TARGET_FILE"

    user@host:~$ osascript
    -e 'tell application "Finder"'
    -e "make new alias to file (posix file "$FULL_PATH_TO_TARGET_FILE") at desktop"
    -e 'end tell'

    alias file alias-target of folder Desktop of folder user of folder Users of disk MacHD


    Then I verified the Alias using the getTrueName program:



    user@host:~$ ./getTrueName ~/Desktop/alias-target

    /tmp/alias-target


    Victory!



    The blog post Stupid Mac OS X Tricks: Resolving Aliases also looks like it might have a solution. It contained the following Perl script:



    #!/usr/local/bin/perl
    use Mac::Errors;
    use Mac::Files;
    use Mac::Resources;

    my $path = '/Users/pudge/Desktop/some alias';
    my $res = FSpOpenResFile($path, 0) or die $Mac::Errors::MacError;
    # get resource by index; get first "alis" resource
    my $alis = GetIndResource('alis', 1) or die $Mac::Errors::MacError;
    my $link = ResolveAlias($alis);
    print $link;


    I didn't have the required libraries and I didn't feel like installing a bunch of stuff, so I gave up on this one.



    I also found the mac_alias, which seemed promising. I spent 5 or 10 minutes messing around with it, but wasn't able to figure out how to resolve an alias target.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 14 '17 at 2:46

























    answered Dec 8 '17 at 0:01









    igal

    4,830930




    4,830930











    • Thanks for the answer. This works great. I'd also like to know how to find the original referent file, given that the alias no longer points to it. There's tons of these broken alias links that need to be resolved. I'd like to use one script that finds all aliases and, for each one, finds its referent. Is that possible? Thanks.
      – ericlindellnyc
      Dec 13 '17 at 17:07










    • @ericlindellnyc Ok, I think I found what you're looking for. I included links to all of my references - hopefully it's not too disorganized. Let me know what you think.
      – igal
      Dec 14 '17 at 2:47
















    • Thanks for the answer. This works great. I'd also like to know how to find the original referent file, given that the alias no longer points to it. There's tons of these broken alias links that need to be resolved. I'd like to use one script that finds all aliases and, for each one, finds its referent. Is that possible? Thanks.
      – ericlindellnyc
      Dec 13 '17 at 17:07










    • @ericlindellnyc Ok, I think I found what you're looking for. I included links to all of my references - hopefully it's not too disorganized. Let me know what you think.
      – igal
      Dec 14 '17 at 2:47















    Thanks for the answer. This works great. I'd also like to know how to find the original referent file, given that the alias no longer points to it. There's tons of these broken alias links that need to be resolved. I'd like to use one script that finds all aliases and, for each one, finds its referent. Is that possible? Thanks.
    – ericlindellnyc
    Dec 13 '17 at 17:07




    Thanks for the answer. This works great. I'd also like to know how to find the original referent file, given that the alias no longer points to it. There's tons of these broken alias links that need to be resolved. I'd like to use one script that finds all aliases and, for each one, finds its referent. Is that possible? Thanks.
    – ericlindellnyc
    Dec 13 '17 at 17:07












    @ericlindellnyc Ok, I think I found what you're looking for. I included links to all of my references - hopefully it's not too disorganized. Let me know what you think.
    – igal
    Dec 14 '17 at 2:47




    @ericlindellnyc Ok, I think I found what you're looking for. I included links to all of my references - hopefully it's not too disorganized. Let me know what you think.
    – igal
    Dec 14 '17 at 2:47












    up vote
    0
    down vote













    I might have figured out how to locate referent files for symlinks that are broken.



    [Btw, I'm the OP -- couldn't find original loginfo, so I signed up anew.]



    Use a duplicate file finder like dupeGuru. Set it to
    o Search entire directory/drives containing symlinks and referents.
    o Mix files of different types.
    o Inexact matches are okay (i.e., certainty-level around 80%).
    o Match filename only (not content or entire directory).



    This will turn up many false positives, but it will include symlinks and their referents (broken or intact).






    share|improve this answer
























      up vote
      0
      down vote













      I might have figured out how to locate referent files for symlinks that are broken.



      [Btw, I'm the OP -- couldn't find original loginfo, so I signed up anew.]



      Use a duplicate file finder like dupeGuru. Set it to
      o Search entire directory/drives containing symlinks and referents.
      o Mix files of different types.
      o Inexact matches are okay (i.e., certainty-level around 80%).
      o Match filename only (not content or entire directory).



      This will turn up many false positives, but it will include symlinks and their referents (broken or intact).






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        I might have figured out how to locate referent files for symlinks that are broken.



        [Btw, I'm the OP -- couldn't find original loginfo, so I signed up anew.]



        Use a duplicate file finder like dupeGuru. Set it to
        o Search entire directory/drives containing symlinks and referents.
        o Mix files of different types.
        o Inexact matches are okay (i.e., certainty-level around 80%).
        o Match filename only (not content or entire directory).



        This will turn up many false positives, but it will include symlinks and their referents (broken or intact).






        share|improve this answer












        I might have figured out how to locate referent files for symlinks that are broken.



        [Btw, I'm the OP -- couldn't find original loginfo, so I signed up anew.]



        Use a duplicate file finder like dupeGuru. Set it to
        o Search entire directory/drives containing symlinks and referents.
        o Mix files of different types.
        o Inexact matches are okay (i.e., certainty-level around 80%).
        o Match filename only (not content or entire directory).



        This will turn up many false positives, but it will include symlinks and their referents (broken or intact).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 27 '17 at 17:09









        Eric Schayer

        11




        11



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409589%2fhow-can-i-locate-all-mac-os-x-alias-files-and-find-their-target-files-despite%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)