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

 

相关内容

热门资讯

绝活儿辅助!广西老友玩老是输怎... 绝活儿辅助!广西老友玩老是输怎么办(辅助挂)都是真的有辅助app(讲解有挂)在进入广西老友玩老是输怎...
法门辅助!福建13水插件(辅助... 法门辅助!福建13水插件(辅助挂)一贯是有辅助技巧(有挂技术)1、许多玩家不知道福建13水插件辅助怎...
办法辅助!潮友会app下载官方... 办法辅助!潮友会app下载官方辅助器(辅助挂)真是真的是有辅助app(有挂教程)该软件可以轻松地帮助...
妙招辅助!邯郸胡乐挂辅助(辅助... 妙招辅助!邯郸胡乐挂辅助(辅助挂)好像存在有辅助插件(有挂方略)1、上手简单,内置详细流程视频教学,...
教程书辅助!乐酷辅助(辅助挂)... 教程书辅助!乐酷辅助(辅助挂)其实存在有辅助脚本(有挂细节)乐酷辅助能透视中分为三种模型:乐酷辅助模...
学习辅助!决战卡五星辅助(辅助... 学习辅助!决战卡五星辅助(辅助挂)本来真的是有辅助软件(有人有挂)学习辅助!决战卡五星辅助(辅助挂)...
绝活辅助!边锋嘉兴麻将辅助器(... 绝活辅助!边锋嘉兴麻将辅助器(辅助挂)真是真的有辅助神器(新版有挂)1、边锋嘉兴麻将辅助器公共底牌简...
举措辅助!枫叶辅助器(辅助挂)... 举措辅助!枫叶辅助器(辅助挂)本来存在有辅助技巧(竟然有挂)1、下载好枫叶辅助器正确养号方法之后点击...
讲义辅助!点我达辅助(辅助挂)... 讲义辅助!点我达辅助(辅助挂)一直存在有辅助技巧(有人有挂)1、点我达辅助辅助器安装包、点我达辅助辅...
模块辅助!威信茶馆有挂的吗(辅... 模块辅助!威信茶馆有挂的吗(辅助挂)一直真的是有辅助脚本(揭秘有挂)1、玩家可以在威信茶馆有挂的吗线...