前些天在跟大伙讨论linux查找文件速度的问题;大家都一致决定
find [path] -name "keyword"
太慢了,而且太浪费cpu了;有木有一个比较好的idea吗?当然有了。
locate 初入linux道行的,或者是接触一年半载的人很少经常用他;可能他比find多了两个字母吧;并且没有find好记;所以就被初学者遗忘在角落里面;
[10:53 @ stm32 ]$ locate -h
Usage: locate [OPTION]... [PATTERN]...
Search for entries in a mlocate database.
-b, --basename match only the base name of path names
-c, --count only print number of found entries
-d, --database DBPATH use DBPATH instead of default database (which is
/var/lib/mlocate/mlocate.db)
-e, --existing only print entries for currently existing files
-L, --follow follow trailing symbolic links when checking file
existence (default)
-h, --help print this help
-i, --ignore-case ignore case distinctions when matching patterns
-l, --limit, -n LIMIT limit output (or counting) to LIMIT entries
-m, --mmap ignored, for backward compatibility
-P, --nofollow, -H don‘t follow trailing symbolic links when checking file
existence
-0, --null separate entries with NUL on output
-S, --statistics don‘t search for entries, print statistics about each
used database
-q, --quiet report no error messages about reading databases
-r, --regexp REGEXP search for basic regexp REGEXP instead of patterns
--regex patterns are extended regexps
-s, --stdio ignored, for backward compatibility
-V, --version print version information
-w, --wholename match whole path name (default)
Report bugs to mitr@redhat.comlocate命令可以在搜寻数据库时快速找到档案,数据库由updatedb程序来更 新,updatedb是由cron daemon周期性建立的,locate命令在搜寻数据库时比由整个由硬盘资料来搜寻资料来得快,但较差劲的是locate所找到的档案若是最近才建立或 刚更名的,可能会找不到,在内定值中,updatedb每天会跑一次,可以由修改crontab来更新设定值。(etc/crontab)[10:59 @ stm32 ]$ sudo updatedb [10:59 @ stm32 ]$ locate xxxxx [11:00 @ stm32 ]$ locate xxxx /home/chenzhenwei/embededproject/platform/s3c24x0/kernel/linux-3.0/arch/arm/mach-omap2/sdram-numonyx-m65kxxxxam.h /home/chenzhenwei/embededproject/platform/s3c24x0/kernel/linux-3.0/drivers/scsi/3w-xxxx.c /home/chenzhenwei/embededproject/platform/s3c24x0/kernel/linux-3.0/drivers/scsi/3w-xxxx.h /home/chenzhenwei/embededproject-code/platform/s3c24x0/kernel/linux-3.0/arch/arm/mach-omap2/sdram-numonyx-m65kxxxxam.h /home/chenzhenwei/embededproject-code/platform/s3c24x0/kernel/linux-3.0/drivers/scsi/3w-xxxx.c /home/chenzhenwei/embededproject-code/platform/s3c24x0/kernel/linux-3.0/drivers/scsi/3w-xxxx.h /home/chenzhenwei/fl2440/kernel/linux-3.0/arch/arm/mach-omap2/sdram-numonyx-m65kxxxxam.h /home/chenzhenwei/fl2440/kernel/linux-3.0/drivers/scsi/3w-xxxx.c /home/chenzhenwei/fl2440/kernel/linux-3.0/drivers/scsi/3w-xxxx.h /home/chenzhenwei/fl2440/linux-3.0/arch/arm/mach-omap2/sdram-numonyx-m65kxxxxam.h /home/chenzhenwei/fl2440/linux-3.0/drivers/scsi/3w-xxxx.c /home/chenzhenwei/fl2440/linux-3.0/drivers/scsi/3w-xxxx.h /lib/modules/2.6.32-220.el6.i686/kernel/drivers/scsi/3w-xxxx.ko /opt/buildroot-2011.11/output/toolchain/linux-2.6.37/arch/arm/mach-omap2/sdram-numonyx-m65kxxxxam.h /opt/buildroot-2011.11/output/toolchain/linux-2.6.37/drivers/scsi/3w-xxxx.c /opt/buildroot-2011.11/output/toolchain/linux-2.6.37/drivers/scsi/3w-xxxx.h /usr/share/foomatic/db/source/printer/Panasonic-KX-Pxxxx_24-pin.xml /usr/src/kernels/2.6.32-220.el6.i686/include/config/blk/dev/3w/xxxx /usr/src/kernels/2.6.32-220.el6.i686/include/config/blk/dev/3w/xxxx/raid.h [11:00 @ stm32 ]$也许这个可以给你带来很多方便;
原文:http://blog.csdn.net/ieczw/article/details/20283421