unix或linux下使用locate指令在其数据库中查询文件要比find更快更高效
jjkklldeMBP:defaults jjkkll$ locate type
WARNING: The locate database (/var/db/locate.database) does not exist.
To create the database, run the following command:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
Please be aware that the database can take some time to generate; o
根据提示,我们需要创建它的数据库:
jjkklldeMBP:defaults jjkkll$ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
Password:
尝试一下搜索的命令:
jjkklldeMBP:defaults jjkkll$ locate .doc
WARNING: The locate database (/var/db/locate.database) does not exist.
To create the database, run the following command:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
Please be aware that the database can take some time to generate; once
the database has been created, this message will no longer appear.
看来是要一段时间来生成数据库,喝杯咖啡,回来,再试:
jjkklldeMBP:defaults jjkkll$ locate .doc
/Applications/App Store.app/Contents/PlugIns/DockTile.docktileplugin
/Applications/App Store.app/Contents/PlugIns/DockTile.docktileplugin/Contents
/Applications/App Store.app/Contents/PlugIns/DockTile.docktileplugin/Contents/Info.plist
/Applications/App Store.app/Contents/PlugIns/DockTile.docktileplugin/Contents/MacOS
/Applications/App Store.app/Contents/PlugIns/DockTile.docktileplugin/Contents/MacOS/DockTile
。。。
已经可以了,再就是更新数据库的updatedb命令了,根据Linux使用经验,使用updatedb命令可以更新locate命令的数据库,而在mac os X下却找不到updatedb这个程序,使用man locate查看,得知locate数据库位置在:
/var/db/locate.datebase
而所谓的updatedb程序在:
/usr/libexec/locate.updatedb
知道了位置直接调用就可以了。
为了省去路径,建立终端下的快捷命令:
vim ~/.bashrc
添加一行:
alias updatedb='/usr/libexec/locate.updatedb'