Какой инструмент является наиболее гибким для поиска по всей моей системе, найдите или mdfind?

777
Billy McCloskey

Следите за Spotlight и команда locate не ищет * все * папки :

Шаги, упомянутые Гордоном Дэвиссоном, были выполнены; .bashrcбыл введен в поле поиска Spotlight, а системные и невидимые файлы были включены согласно приведенной выше ссылке. .bashrcФайл не появлялся вообще. В $химической завивки были изменены с 750до 755и через несколько часов прошло, но до .bashrcсих пор не появлялся.

Что необходимо увидеть .bashrcс помощью Spotlight? Как Spotlight может отображаться .bashrcповсюду, если вообще отображается, чтобы увидеть самый последний, как в ?:

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

( most_recent_fileэто Perl-скрипт, который отображает каждый файл в списке и выводит имя самого нового):

Примечание. locate.updatedbСценарий создания базы данных был изменен, чтобы позволить find выполнять поиск /etc/locate.rcуказанного тома (ов) как rootили nobody, в зависимости от того, вызывает ли он его 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

1 ответ на вопрос

3
Gordon Davisson

I haven't been able to get the Finder's spotlight search to list .bashrc either (perhaps it's finding it, but not displaying because it's invisible?). But the command-line interface to spotlight... well, it can be convinced to show it. This works:

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

But for some reason the -name option doesn't show it:

$ mdfind -name ".bashrc" $ 

...so I don't completely trust this to find what I think it should.

Я изменил атрибут Finder AppleShowAllFiles на true. Я также установил для атрибута «Видимость» «Видимость файла» значение «Видимый» или «Невидимый». Ни один из них не дает видимого невидимого файла из центра внимания, такого как .bashrc. Billy McCloskey 10 лет назад 0
Кажется, больше не работает на macOS Sierra (10.12). Norswap 7 лет назад 1

Похожие вопросы