哪种工具对于搜索我的整个系统最灵活,locate 还是 mdfind?

哪种工具对于搜索我的整个系统最灵活,locate 还是 mdfind?

后续Spotlight 和定位命令不会搜索*所有*文件夹

执行了 Gordon Davisson 提到的步骤;.bashrc在 Spotlight 搜索字段中输入了 ,并根据上述参考启用了系统和不可见文件。.bashrc文件根本没有出现。${HOME}权限从 更改为750755几个小时过去了,但.bashrc仍然没有出现。

使用 Spotlight需要什么.bashrc?Spotlight 如何才能.bashrc在所有地方显示(如果有的话),以便查看最新的一个,例如:

me@My-MacBook-Pro ~
$ locate .bashrc | most_recent_file
/Users/me/.bashrc

most_recent_file是一个 Perl 脚本,它统计列表中的每个文件并打印最新文件的名称):

注意:locate.updatedb数据库创建脚本已更改为允许 find 搜索/etc/locate.rc指定的卷作为rootnobody,具体取决于 或 是否root调用daemon它,如哪些文件夹被“定位”索引/覆盖)。逻辑很棘手,因此这里是更新后的注释/usr/libexec/locate.updatedb

# Modify test for expected invocations by either daemon (id=1) or root (id=0);
# if invoked as root, skip test section and search filesystems as root as per
# /etc/locate.rc, a possible security risk if /etc/locate.rc is not tailored
# for production use.  Invoked as daemon, we "spawn" ourselves as nobody to
# gain nobody's filesystem visability, rather than daemon's.
#if [ "$(id -u)" = "0" ]; then
if [ "$(id -u)" = "1" ]; then

这是脚本的 Perl 源代码。我们的搜索路径中most_recent_file.pl有一个符号链接。most_recent_file

#!/usr/bin/perl -wnl
# From pathname inputs, emits name of one most recently modified
# Gives correct answer where pipelines of this form may not:
#   find . -print | xargs ls –lrdt | tail -1

# NOTE: Use find or locate to provide input, or ls -d dir/*,
# but *not* simply "ls dir" (dir won't be present in pathname)

# Sample invocations:
#      locate '*.c' | most_recent_file
#      ls -d /etc/* | most_recent_file
#      find /local -name 'somescript' | most_recent_file
#      most_recent_file < filelist

BEGIN {
    $newest = 0;    # initialize modification-time reference point
    $name   = "";
}

# Get file's numeric modification time; 10th value from stat
$mtime = ( stat $_ )[9];    # indexing into output of stat
if ( $mtime > $newest ) {   # if True, current file is newest yet seen

    # Remember mod-time for comparison to others,
    # and remember filename for final report
    $newest = $mtime;
    $name   = $_;
}

END {
    print $name;
}

答案1

我也没能使 Finder 的聚光灯搜索列出 .bashrc(也许它找到了它,但因为不可见而没有显示?)。但是聚光灯的命令行界面……好吧,可以让它显示它。这有效:

$ mdfind kMDItemFSName = ".bashrc"
/Users/gordon/.bashrc

但由于某种原因,该-name选项没有显示:

$ mdfind -name ".bashrc"
$

...所以我不完全相信它能找到我认为应该找到的东西。

相关内容