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

 

相关内容

热门资讯

科普攻略!wpk辅助器是真的吗... 科普攻略!wpk辅助器是真的吗,微乐小程序礼包码,都是有辅助辅助(有挂解密)1.微乐小程序礼包码 选...
科普攻略!wepoker新号好... 科普攻略!wepoker新号好一点吗,亿游十三道脚本插件,确实是真的有辅助开挂(揭秘有挂)1、超多福...
教程辅助!pokernow辅助... 教程辅助!pokernow辅助控制,四川微乐微信麻将小程序辅助,切实真的是有辅助脚本(了解有挂)1、...
1.9分钟了解!poker红龙... 1.9分钟了解!poker红龙辅助,拱趴大菠萝的辅助器,确实存在有辅助辅助(有挂教程)在进入拱趴大菠...
科技介绍!pokermaste... 科技介绍!pokermaster修改器,哈糖大菠萝挂,确实是有辅助脚本(有挂存在)pokermast...
最新技巧!如何下载wepoke... 最新技巧!如何下载wepoker安装包,闲来软件辅助,确实真的是有辅助脚本(有挂存在)一、闲来软件辅...
科技新动态!werplan辅助... 科技新动态!werplan辅助软件,广西友乐app辅助工具,一直是真的有辅助安装(有挂讲解)1、广西...
科技分享!约局吧开挂神器是真的... 科技分享!约局吧开挂神器是真的吗,决战卡五星游戏修改器,都是存在有辅助教程(有挂攻略)1)约局吧开挂...
推荐十款!hhpoker透视工... 推荐十款!hhpoker透视工具,广西友乐辅助app,真是存在有辅助安装(有挂秘笈);1、每一步都需...
科技揭秘!werplan辅助软... 科技揭秘!werplan辅助软件,来几局免费辅助器,本来是真的有辅助安装(有挂解密)1、实时来几局免...