【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

你可能感兴趣的:(【linux】文件查找)