Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1779137
  • 博文数量: 276
  • 博客积分: 1574
  • 博客等级: 上尉
  • 技术积分: 2894
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-26 23:23
个人简介

生活的美妙在于,不知道一下秒是惊艳还是伤神,时光流转,珍惜现在的拥有的时光

文章分类

全部博文(276)

文章存档

2017年(17)

2016年(131)

2015年(63)

2013年(2)

2012年(32)

2011年(31)

分类: LINUX

2016-04-27 12:39:15

mlocate命令简介:
m取自merging.
locate命令用于查找文件,因为有索引,它比find命令的搜索速度要快得多,它需要一个数据库/var/lib/mlocate/mlocate.db(默认值,可以通过updatedb -O filepath修改),这个数据库可以由每天的例行工作(crontab)程序来建立。当我们建立好这个索引数据库后,就可以方便地来搜寻所需文件了;缺点是比较新创建的文件locate还没有收入数据库中,可能无法查询到。
如搜索mlocate.db
[12:12 root .../lib/mlocate]# locate mlocate.db
/usr/share/man/man5/mlocate.db.5.gz
/var/lib/mlocate/mlocate.db
/var/lib/mlocate/mlocate.db.tzIS3b

即先运行:updatedb,生成索引文件mlocate.db后实现快速查找。
[12:04 t /etc/cron.hourly]$ updatedb --help
用法: updatedb [OPTION]...
更新 mlocate 数据库。

  -f, --add-prunefs FS           也忽略 FS
  -n, --add-prunenames NAMES     也忽略 NAMES
  -e, --add-prunepaths PATHS     也忽略 PATHS
  -U, --database-root PATH       向数据库中存储的子树 (默认 "/")
  -h, --help                     显示这份帮助
  -o, --output FILE              要升级的数据库 (默认
                                 `/var/lib/mlocate/mlocate.db')
      --prune-bind-mounts FLAG   忽略绑定装载 (默认 "no")
      --prunefs FS               从数据库中忽略的文件系统
      --prunenames NAMES         从数据库中忽略的目录名
      --prunepaths PATHS         从数据库中忽略的路径
  -l, --require-visibility FLAG  在报告文件之前检查可见性
                                 (默认 "yes")
  -v, --verbose                  当文件被找到时显示其路径
  -V, --version                  显示版本信息
配置默认为从文件`/etc/updatedb.conf' 读取的值。
.

将 bug 报告给 mitr@redhat.com.

updatedb的配置文件在/etc/updatedb.conf
[12:05 root .../lib/mlocate]# cat /etc/updatedb.conf
PRUNE_BIND_MOUNTS = "yes"
PRUNEFS = "9p afs anon_inodefs auto autofs bdev binfmt_misc cgroup cifs coda configfs cpuset debugfs devpts ecryptfs exofs fuse fuse.sshfs fusectl gfs gfs2 gpfs hugetlbfs inotifyfs iso9660 jffs2 lustre mqueue ncpfs nfs nfs4 nfsd pipefs proc ramfs rootfs rpc_pipefs securityfs selinuxfs sfs sockfs sysfs tmpfs ubifs udf usbfs ceph fuse.ceph"
PRUNENAMES = ".git .hg .svn .bzr .arch-ids {arch} CVS"
PRUNEPATHS = "/afs /media /mnt /net /sfs /tmp /udev /var/cache/ccache /var/lib/yum/yumdb /var/lib/dnf/yumdb /var/spool/cups /var/spool/squid /var/tmp /var/lib/ceph"
[12:05 root .../lib/mlocate]#

mlocate系统主要文件如下
[12:16 root ~]# rpm -ql mlocate.x86_64
/etc/updatedb.conf
/usr/bin/locate    #用于查找文件
/usr/bin/updatedb    #用于更新数据库
/usr/lib/systemd/system/mlocate-updatedb.service
/usr/lib/systemd/system/mlocate-updatedb.timer
/usr/libexec/mlocate-run-updatedb
...
/var/lib/mlocate
/var/lib/mlocate/mlocate.db    #数据库
[12:19 root ~]# cat /usr/lib/systemd/system/mlocate-updatedb.timer
[Unit]
Description=Updates mlocate database every day

[Timer]
OnCalendar=daily
AccuracySec=24h
Persistent=true

[Install]
WantedBy=timers.target
最新版的fedora系统使用systemctl的timer控制mlocate的定时执行.
[12:18 root ~]# cat /usr/lib/systemd/system/mlocate-updatedb.service
[Unit]
Description=Update a database for mlocate

[Service]
ExecStart=/usr/libexec/mlocate-run-updatedb
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7

PrivateTmp=true
PrivateDevices=true
PrivateNetwork=true
ProtectSystem=true
mlocate.db(5)                                                                                File Formats Manual                                                                                mlocate.db(5)

NAME
       mlocate.db - a mlocate database

DESCRIPTION
       A mlocate database starts with a file header: 8 bytes for a magic number ("\0mlocate" like a C literal), 4 bytes for the configuration block size in big endian, 1 byte for file format version (0), 1
       byte for the “require visibility” flag (0 or 1), 2 bytes padding, and a NUL-terminated path name of the root of the database.

       The header is followed by a configuration block, included to ensure databases are not reused if some configuration changes could affect their contents.  The size of the configuration block in  bytes
       is  stored  in  the file header.  The configuration block is a sequence of variable assignments, ordered by variable name.  Each variable assignment consists of a NUL-terminated variable name and an
       ordered list of NUL-terminated values.  The value list is terminated by one more NUL character.  The ordering used is defined by the strcmp () function.

       Currently defined variables are:

       prune_bind_mounts
              A single entry, the value of PRUNE_BIND_MOUNTS; one of the strings 0 or 1.

       prunefs
              The value of PRUNEFS, each entry is converted to uppercase.

       prunepaths
              The value of PRUNEPATHS.

       The rest of the file until EOF describes directories and their contents.  Each directory starts with a header: 8 bytes for directory time  (seconds)  in  big  endian,  4  bytes  for  directory  time
       (nanoseconds)  in  big endian (0 if unknown, less than 1,000,000,000), 4 bytes padding, and a NUL-terminated path name of the the directory.  Directory contents, a sequence of file entries sorted by
       name, follow.

       Directory time is the maximum of st_ctime and st_mtime of the directory.  updatedb(8) uses the original data if the directory time in the database and in the file system  match  exactly.   Directory
       time equal to 0 always causes rescanning of the directory: this is necessary to handle directories which were being updated while building the database.

       Each file entry starts with a single byte, marking its type:

       0      A non-directory file.  Followed by a NUL-terminated file (not path) name.

       1      A subdirectory.  Followed by a NUL-terminated file (not path) name.

       2      Marks the end of the current directory.

       locate(1)  only  reports  file  entries,  directory names are not reported because they are reported as an entry in their parent directory.  The only exception is the root directory of the database,
       which is stored in the file header.

AUTHOR
       Miloslav Trmac

SEE ALSO
       locate(1), updatedb.conf(5), updatedb(8)

mlocate                                                                                            Jan 2007                                                                                     mlocate.db(5)

阅读(2665) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~