得分
133
Advertisement
答案 (7)
解决方案找到了!
Advertisement
Advertisement
得分
10
2010-12-28 19:21:39 +0000
mdfind命令使用Spotlight数据库
http://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/mdfind.1.html
Rich Homolka
http://superuser.stackexchange.com/users/39436
Advertisement
得分
2
2018-02-09 04:28:07 +0000
你可以使用下面的命令行函数来快速找到并打开相关文件。我发现这比在 spotlight 窗口中输入长长的查询字符串要容易得多。
在 ~/.bash_aliases 中添加以下函数。要在文件名中任意位置搜索带单词、派和2016的文件,请做
# find any item matching search query in file name
spot(){
mdfind "kMDItemDisplayName=='*$1*'cd";
}
# restrict to files under (recursive) a specific path
findpaper(){
mdfind -onlyin "/Users/foo/articles" "kMDItemDisplayName=='*$1*'cd";
}
# default to open the first entry unless 2nd positional argument is given
openpaper(){
FILEID=$(printf "%sp" ${2:-1})
open "$(mdfind -name -onlyin "/Users/foo/articles" "kMDItemDisplayName=='*$1*'cd" | sed -n "${FILEID}")"
不需要在查询前加上或附加source ~/.bash_aliases作为查询模式,*已经在查询的开头和结尾处标记了通配符条目。附加的'*$1*'是不区分大小写,并且忽略了二进制符号,例如,cd会同时返回Frédéric和FrEDeric。为了避免打开bash脚本或其他非文档文件,你可以通过附加的搜索属性来限制文件内容。有关使用其他搜索操作符的使用,请参阅 文件元数据查询表达式语法 和 https://ss64.com/osx/mdfind.html 。
Advertisement
得分
0
2019-06-09 11:50:48 +0000
从/
sudo find / &> ~/file-list.txt
sudo chown $(whoami) ~/file-list.txt
cat ~/file-list.txt | grep abc.dmg
捕获磁盘上的每一个文件作为根目录,通过grep搜索整个硬盘:
cat ~/file-list.txt | grep -E "(\.dmg|\.jpg)"
使用正则表达式只显示.jpg和.dmg文件:
Applications/Visualisations/CurvedSpaces-forMac.app/Contents/Resources/Textures/paper.jpg
结果:
&001
…等。不幸的是,它也会捕获所有挂载的磁盘,所以最好把那些时间机器的磁盘弹出,因为它们有很多链接。所以在另一个窗口中,我运行了watch tail -n 10 ~/file-list.txt,这让我看到了我的黑客程序中的情况。