如何查询所有Finder别名的目标?

发布于 2024-10-18 21:07:03 字数 274 浏览 8 评论 0原文

Mac OSX 10.6

我有一些别名指向错误的卷。我想在我的整个层次结构中搜索此类别名。它们是别名,而不是符号链接,所以我不能只做find / -type l -ls | grep badVolumeName.

别名似乎有一个 com.apple.ResourceFork,但是使用 xattr 查询它会得到二进制数据。有没有办法将别名的目标转储为文本,以便我可以 grep 查找错误的卷名称?或者还有什么其他方法可以做到这一点?

Mac OSX 10.6

I've got some aliases that are pointing to the wrong volume. I'd like to search my whole hierarchy for such aliases. They're aliases, not symlinks, so I can't just do find / -type l -ls | grep badVolumeName.

It seems that aliases have a com.apple.ResourceFork, but querying this with xattr gives me binary data. Is there a way to dump the target of the alias as text so I can grep for the bad volume name? Or what's another way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏末染殇 2024-10-25 21:07:03

要查找别名文件,您可以使用StackOverflow 上的此答案。首先,创建一个脚本 is_alias.sh

#! /bin/bash
[ "$(mdls -raw -name kMDItemKind "$1")" = "Alias" ]

然后运行

find . -type f -exec ./is_alias.sh {} \; -print

​​获取别名的路径似乎相当困难。

有人发布了使用 MacPerl 的解决方案,但我没有MacPerl 我没有测试过这个,不知道它是否有效。

AskDifferent 上有一个类似的问题,有几个不同的建议,但似乎都没有真正解决问题。 Applescript 的答案是好的,但是获取别名文件的“原始项目”这一关键操作似乎不适用于损坏的别名。

您还可以查看这个问题,其中可能有一些Cocoa解决方案。

To find alias files you can make use of this answer on StackOverflow. First, create a script is_alias.sh:

#! /bin/bash
[ "$(mdls -raw -name kMDItemKind "$1")" = "Alias" ]

and then run

find . -type f -exec ./is_alias.sh {} \; -print

Getting the path of an alias seems quite difficult.

Someone has posted a solution using MacPerl, but as I do not have MacPerl I haven't tested this and don't know whether it works.

There is a similar question on AskDifferent, with several different suggestions, but none of them seem to actually solve the problem. The Applescript answer is okay, but the key operation, getting the "original item" of an alias file, doesn't seem to work for broken aliases.

You can also take a look at this question which might have some Cocoa solutions.

执手闯天涯 2024-10-25 21:07:03

bash 脚本对我不起作用,因为我在 zsh 中运行它。所以我用 find: 运行了下面的 perl 脚本

find . -type f -print0|xargs -0 isAlias.pl

,这是 perl 脚本:

#!/usr/bin/perl -w

while ( my $name = shift @ARGV ) {
  #print $name;

  open my $fh, "-|", ( 'mdls', '-n', 'kMDItemKind', '--', $name ) or die "Failed spawning mdls on '$name': $!";
  my @output_lines = <$fh>;
  close $fh;
  #print " ", scalar @output_lines, " ";
  #print "'", @output_lines, "'\n";
  #chomp $output_lines[0];
  
  $output_lines[0] =~ m/kMDItemKind = "([^"]+)"/ or die "Failed getting ItemKind: $!";

  my $kind = $1;

  if ($kind =~ m/Alias/) {
    print "'$name' is an alias\n";
  }
  #else {
  #    print "\n";
  #}
}

the bash script didn't work for me because I was running it in zsh. so I ran the below perl script with find:

find . -type f -print0|xargs -0 isAlias.pl

and here's the perl script:

#!/usr/bin/perl -w

while ( my $name = shift @ARGV ) {
  #print $name;

  open my $fh, "-|", ( 'mdls', '-n', 'kMDItemKind', '--', $name ) or die "Failed spawning mdls on '$name': $!";
  my @output_lines = <$fh>;
  close $fh;
  #print " ", scalar @output_lines, " ";
  #print "'", @output_lines, "'\n";
  #chomp $output_lines[0];
  
  $output_lines[0] =~ m/kMDItemKind = "([^"]+)"/ or die "Failed getting ItemKind: $!";

  my $kind = $1;

  if ($kind =~ m/Alias/) {
    print "'$name' is an alias\n";
  }
  #else {
  #    print "\n";
  #}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文