Linux查找类命令
创始人
2024-10-22 02:35:58
0

Linux查找类命令

文章目录

  • Linux查找类命令
    • 1.whereis
    • 2.locate
    • 3.find
    • 4.which
    • 5.grep
  • Use graphical install

1.whereis

(1)whereis -b:只所搜二进制文件

[root@luo ~]# whereis -b ls ls: /usr/bin/ls [root@luo ~]#  

(2)whereis -m:只搜索man文档

[root@luo ~]# whereis -m ls ls: /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz [root@luo ~]#  

(3)whereis -s:只所搜代码文件

[root@luo ~]# whereis -s ls ls: [root@luo ~]#  

2.locate

(1)locate:列出所有匹配到的文件

[root@luo ~]# locate passwd /etc/passwd /etc/passwd- /etc/pam.d/passwd /etc/security/opasswd /usr/bin/gpasswd /usr/bin/grub2-mkpasswd-pbkdf2 ...... 

(2)locate -c passwd:只输出查找到的文件数量

[root@luo ~]# locate -c passwd 132 [root@luo ~]# 

3.find

(1)语法:find 路径 匹配表达式 -exec command

(2)匹配表达式

-name filename:对指定文件进行查找

-iname filename:文件匹配时不区分大小写

-user username:根据归属用户来查找

-group groupname:根据概述组群查找

-uid:根据uid查找

-gid:根据gid查找

-nouser:查找没有属主的文件,当用户被删除的情况下产生的文件,只有uid没有属主

-nogroup:查找没有属组的文件,当用户被删除的情况下产生的文件,只有gid没有属组

-type:根据文件类型查找,文件类型:b(块设备文件)、c(字符设备文件)、d(目录)、p(管道文件)、l(符号链接文件)、f(普通文件)

-size:根据文件大小进行查找,+表示大于,-表示小于,需要带上文件大小单位

-exec command {} ;:对于匹配的文件执行命令

(3)find /etc -name passwd:查找/etc下所有名称为passwd的文件

[root@luo ~]# find /etc -name passwd /etc/pam.d/passwd /etc/passwd [root@luo ~]#  

(4)find /etc -name passwd -exec cp -a {} /root/files ;:查找/etc下所有名称为passwd的文件并复制到指定目录

[root@luo ~]# find /etc -name passwd -exec cp -a {} /path/to \; [root@luo ~]# cd /path/to [root@luo to]# ls passwd  test [root@luo to]#  

(5)find /etc -name firefox*.rpm:查找/etc下以firefox开头以.rpm结尾的文件

[root@luo ~]# find /usr -name passwd*.gz /usr/share/man/man3/passwd2des.3.gz /usr/share/man/man5/passwd.5.gz /usr/share/man/man1/passwd.1ossl.gz /usr/share/man/man1/passwd.1.gz /usr/share/man/ja/man1/passwd.1.gz [root@luo ~]#  

(6)find /etc -type f -exec ls -l {} ;:查找/etc下的目录文件并且查看详细信息

[root@luo to]# find /etc -type f -exec ls -l {} \; -rw-r--r--. 1 root root 666  7月 19 10:59 /etc/fstab -rw-------. 1 root root 0  7月 19 10:59 /etc/crypttab -rw-r--r--. 1 root root 255  7月 19 10:59 /etc/lvm/devices/system.devices  

(7)find /etc -size +5M:查找/etc下大于5M的文件

[root@luo ~]# find /etc -size +5M /etc/udev/hwdb.bin [root@luo ~]#  

4.which

(1)which ls:查找ls命令的绝对路径

[root@luo ~]# which ls alias ls='ls --color=auto'         /usr/bin/ls [root@luo ~]#  

5.grep

(1)grep -i root filename:查找指root的行时忽略大小写

[root@luo ~]# grep -i root anaconda-ks.cfg # Root password rootpw --iscrypted --allow-ssh $6$Ur6GOX5SKwiufOix$0.u8uPYIrp9e/pdvbuA87evChC0fiCN19RRBs9RqxWoy8U/Ird44SXWNROiB5oLU6LUvpYpVXBug2GZYSeegm0 [root@luo ~]#  

(2)grep -n root filename:查找root的行并显示行号

[root@luo ~]# grep -n root anaconda-ks.cfg 41:rootpw --iscrypted --allow-ssh $6$Ur6GOX5SKwiufOix$0.u8uPYIrp9e/pdvbuA87evChC0fiCN19RRBs9RqxWoy8U/Ird44SXWNROiB5oLU6LUvpYpVXBug2GZYSeegm0 [root@luo ~]#  

(3)grep -v root filenmae:反向选择,列出不匹配的行

[root@luo ~]# grep -v root anaconda-ks.cfg # Generated by Anaconda 34.25.3.8 # Generated by pykickstart v3.32 #version=RHEL9 # Use graphical install graphical repo --name="AppStream" --baseurl=file:///run/install/sources/mount-0000-cdrom/AppStream ...... 

y pykickstart v3.32
#version=RHEL9

Use graphical install

graphical
repo --name=“AppStream” --baseurl=file:///run/install/sources/mount-0000-cdrom/AppStream

 

相关内容

热门资讯

透视烘培!pokemmo辅助器... 您好,pokemmo辅助器手机版下载这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275...
透视教材!拱趴大菠萝开挂方法,... 透视教材!拱趴大菠萝开挂方法,聚星ai辅助工具下载(透视)本来真的有透视神器(哔哩哔哩)1、不需要A...
第六分钟插件!微信小程序免费黑... 第六分钟插件!微信小程序免费黑科技,微乐小程序辅助工具哪里下载(本来是真的外挂app)-哔哩哔哩1、...
透视练习!hh poker辅助... 透视练习!hh poker辅助器先试用,hhpoker作必弊码(透视)原来存在有挂(哔哩哔哩)1、玩...
透视操作!wepoker有插件... 透视操作!wepoker有插件吗,wepoker透视底牌(透视)一直有透视插件(哔哩哔哩)1、超多福...
两分钟辅助!微乐小程序自建房透... 两分钟辅助!微乐小程序自建房透视下载,微乐自建房免费黑科技推荐(本来是真的外挂插件)-哔哩哔哩1、下...
透视大纲!哈糖大菠萝助手,德扑... 透视大纲!哈糖大菠萝助手,德扑之心免费透视(透视)竟然是有挂(哔哩哔哩)1、德扑之心免费透视免费脚本...
透视办法!aa poker辅助... 透视办法!aa poker辅助包,云扑克有透视吗(透视)好像真的是有脚本器(哔哩哔哩)1、首先打开云...
透视步骤!wepoker透视脚... 透视步骤!wepoker透视脚本免费app,impoker辅助(透视)原来是真的挂(哔哩哔哩)1、w...
第8分钟脚本!微信小程序免费黑... 第8分钟脚本!微信小程序免费黑科技,微信小程序微乐辅助器免费版v2.0免费(一直是真的外挂修改器)-...