linux-文件查找

查找文件

一般查找find

最常用的方式find PATH -name FILENAME.例如查找当前用户目录下的1.txt文件,find ~ -name 1.txt.同时还可以使用*号匹配.如果想忽略文件名的大小写,可以添加-iname参数.

[zengchao@localhost dir]$ tree
.
├── 1.txt
├── 2.txt
├── A.doc
├── b.doc
└── child
    ├── c1.txt
    └── c2.doc

3 directories, 4 files
[zengchao@localhost dir]$ find ./ -name 1.txt 
./1.txt
[zengchao@localhost dir]$ find ./ -name a.doc 
[zengchao@localhost dir]$ find ./ -iname a.doc
./A.doc
[zengchao@localhost dir]$ find ./ -name '*.txt'
./1.txt
./2.txt
./child/c1.txt

数据库查找:locate

locate命令查找数据会依赖本地的数据库文件,默认每天会检索一遍系统中的文件,然后记录到数据库中.也可以使用命令updatedb手动更新数据库文件.例如下面的操作:

[zengchao@localhost ~]$ touch zengchao_test.file
[zengchao@localhost ~]$ locate zengchao_test.file
[zengchao@localhost ~]$ sudo updatedb
[zengchao@localhost ~]$ locate zengchao_test.file
/home/zengchao/zengchao_test.file
[zengchao@localhost ~]$ rm -rf zengchao_test.file 
[zengchao@localhost ~]$ locate zengchao_test.file
/home/zengchao/zengchao_test.file
[zengchao@localhost ~]$ sudo updatedb
[zengchao@localhost ~]$ locate zengchao_test.file

首先创建了一个文件,然后使用locate去查找,但是并没有查找到,接着我手动更新数据库文件,可以找到该文件.然后我删除刚创建的文件,接着查找还是能找到,然后再次更新数据库文件,这个时候就无法找到了.

which/whereis

which用于从系统的PATH变量所定义的目录中查找可执行的文件绝对路径.例如超找passwd这个命令在系统中的绝对路径.

[zengchao@localhost ~]$ which passwd
/bin/passwd

whereis查找也能查找到器路径,但是与which不用的是,它不但能找出其二进制文件,还能找出相关的man文件.

zengchao@localhost ~]$ whereis passwd
passwd: /usr/bin/passwd /etc/passwd /usr/share/man/man1/passwd.1.gz /usr/share/man/man5/passwd.5.gz
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • which 查看可执行文件的位置 命令格式:which 可执行文件名称 命令功能:which指令会在PATH变量指...
    upupSue阅读 3,994评论 0 1
  • which 格式: which + cmd作用: 在Path变量指定的路径中,搜索某个系统命令的位置,并且返回第...
    LGmark阅读 3,051评论 0 5
  • Linux下一切皆文件,但是文件由于文件的属性的不同,在查找上可以针对不同的文件做相应的查找以便加快查询速度和减少...
    常青藤成阅读 4,681评论 0 0
  • 我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索:which 查看可执行文件...
    光小月阅读 1,342评论 0 0
  • 《小黑鱼》是美国著名绘本作家李欧.李奥尼创作的绘本故事,故事描写了一条小黑鱼和他的朋友们同心协力,团结合作...
    corawen阅读 20,338评论 2 7

友情链接更多精彩内容