【linux】文件查找

一.find

通过文件名称查找

[root@linux ~]# find -name info
./公共/info
./info

通过文件名模糊匹配

[root@linux ~]# find -name *nfo
./公共/info
./info

指定查找范围

[root@linux ~]# find /etc/gdm -name *.conf
/etc/gdm/custom.conf

通过用户名称查找

[root@linux home]# find /home -user jerry
/home/jerry
/home/jerry/.mozilla
/home/jerry/.mozilla/extensions
/home/jerry/.mozilla/plugins
/home/jerry/.bash_logout
/home/jerry/.bash_profile
/home/jerry/.bashrc
/home/jerry/.cache
/home/jerry/.cache/abrt
/home/jerry/.cache/abrt/lastnotification
/home/jerry/.config
/home/jerry/.config/abrt
/home/jerry/.viminfo
/home/jerry/.bash_history
/home/jerry/jerryinfo
/home/info

指定文件大小

[root@linux home]# find /usr/local -size +100M
/usr/local/GoLand-2022.1/lib/app.jar
/usr/local/GoLand-2022.1/plugins/DatabaseTools/lib/database-plugin.jar
/usr/local/GoLand-2022.1/jbr/lib/libcef.so
二.locate

利用系统自动生成的一个数据库去进行查找,数据库每天自动更新,在查找前可使用updatedb去手动更新数据库

[root@linux ~]#  updatedb
[root@linux ~]# locate goland
/home/go/.config/JetBrains/GoLand2022.1/goland.key
/home/go/.config/JetBrains/GoLand2022.1/goland64.vmoptions
三.which/whereis

which查找命令的相关信息
whereis查找命令所在位置

[root@linux ~]# which ls
alias ls='ls --color=auto'
    /usr/bin/ls
[root@linux ~]# which cd
/usr/bin/cd
[root@linux ~]# whereis which
which: /usr/bin/which /usr/share/man/man1/which.1.gz
四.grep内容过滤

-n显示行号

[root@linux ~]# grep -n one littleprince 
14:But they answered: "Frighten? Why should any one be frightened by a hat?"
21:So then I chose another profession, and learned to pilot airplanes. I have flown a little over all parts of the world; and it is true that geography has been very useful to me. At a glance I can distinguish China from Arizona. If one gets lost in the night, such knowledge is valuable.
25:Whenever I met one of them who seemed to me at all clear-sighted, I tried the experiment of showing him my Drawing Number One, which I have always kept. I would try to find out, so, if this was a person of true understanding. But, whoever it was, he, or she, would always say:

使用管道符|

[root@linux ~]# ls -l | grep .cfg
-rw-------. 1 root root 1850 4月  12 16:31 anaconda-ks.cfg
-rw-r--r--. 1 root root 1898 4月  12 16:32 initial-setup-ks.cfg
五.wc

word count,对文件进行计数统计,分别是行数 单词数 总字节 文件名

[root@linux ~]# wc info
  51  318 1956 info
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • which 查看可执行文件的位置 命令格式:which 可执行文件名称 命令功能:which指令会在PATH变量指...
    upupSue阅读 4,012评论 0 1
  • 对于文件查找,我们最好用的还是属于find命令了,在说find命令之前,先把另外几个查找命令介绍一下。 目录 0x...
    无心_44d4阅读 1,441评论 0 0
  • 在linux下搜索文件只需要几行简单的命令就搞定了,不过不同的指令其功能也是不一样的,使用的时候要灵活选择。 wh...
    AwesomeAshe阅读 2,761评论 0 2
  • find 功能最强的查找文件命令 -size 按文件大小查找,第一个参数为查询目录可以不写查询目录,默认从当前所在...
    Manchangdx阅读 3,199评论 0 0
  • 查找文件 一般查找find 最常用的方式find PATH -name FILENAME.例如查找当前用户目录下的...
    一个菜鸟JAVA阅读 1,531评论 0 3

友情链接更多精彩内容