How to find files quickly in Linux

  
        

A few days ago I was discussing the speed of linux looking for files with everyone; everyone decided that

find [path] -name "keyword"

is too slow and too wasteful Cpu; is there a better idea for wood? Of course there is.

locate The first entry into the linux road, or contact with a year and a half of the people rarely use him often; maybe he has two more letters than find; and no find is easy to remember; so it is a beginner Forgotten in the corner;

[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

Exist

-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 [email protected]

The locate command can quickly find the file when searching the database, the database is updated by the updatedb program, and the updatedb is periodically created by the cron daemon. The locate command is harder than the whole when searching the database. Information to search for information is fast, but the worse is that the file found by locate is only recently established or just renamed, may not be found, in the default value, updatedb will run once a day, you can modify the crontab to update the settings Value. (etc/crontab)

locate is used to search for qualified files. It will store the file and directory name in the database to find files or directories that match the style of the template. Special characters can be used. For example, "*" or "?", etc. to specify the template style, if the specified template is kcpa*ner, locate will find all files or directories whose starting string is kcpa and ending with ner, such as the name If kcpartner is named kcpa_ner, it will list all files including subdirectories in that directory.

The locate command and find find the file function is similar, but locate is to use the update program to create an index database for all files and directory data in the hard disk, directly find the index when executing loacte, the query speed will Faster, the index database is generally managed by the operating system, but it can also be directly updated to force the system to modify the index database immediately.

However, the first time after the update is executed, using locate to find the file will often fail. At this time, execute the locate ˉu command (also execute the updatedb command, the effect is the same) to update the slocate database, the command will Generate a slocate executable file under /usr/sbin, and then locate to the database to find the information you are looking for.

locate: This command requires a background index database as a support at runtime. In Ubuntu this database file is located at /var/cache/locate/locatedb. In general, this database file is automatically updated every day via cron. of. If you are unfortunately not getting an update, you can perform a manual update by executing sudo updatedb.

[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 ]$

Maybe this can bring you Many convenient;

Copyright © Windows knowledge All Rights Reserved