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

 

相关内容

热门资讯

安装程序教程!gg扑克发牌机制... 安装程序教程!gg扑克发牌机制测试(黑科技)外挂ai辅助辅助助手(真的有挂)-哔哩哔哩1、每一步都需...
黑科技免费!aapoker软件... 黑科技免费!aapoker软件app(透视)德州教程(2025已更新)(哔哩哔哩);1、操作简单,无...
一起来讨论!微扑克的辅助工具(... 一起来讨论!微扑克的辅助工具(黑科技)外挂黑科技ai辅助黑科技(有挂透明挂)-哔哩哔哩;一、微扑克的...
黑科技美元局!红龙扑克辅助工具... 黑科技美元局!红龙扑克辅助工具(透视)总结教程(2021已更新)(哔哩哔哩);1、任何红龙扑克辅助工...
解密关于!来玩app德州辅助器... 解密关于!来玩app德州辅助器(黑科技)外挂智能ai辅助器(果真有挂)-哔哩哔哩1、用户打开应用后不...
黑科技线上!aapoker辅助... 黑科技线上!aapoker辅助实际测试(透视)玩家教程(2025已更新)(哔哩哔哩)1、aapoke...
带你了解!来玩德州app辅助软... 带你了解!来玩德州app辅助软件(黑科技)外挂透明挂黑科技辅助神器(有挂方法)-哔哩哔哩1、快速入门...
黑科技神器!wpk免费赛规则(... 黑科技神器!wpk免费赛规则(透视)解密教程(2023已更新)(哔哩哔哩)wpk免费赛规则软件透明挂...
盘点一款!!aa poker智... 盘点一款!!aa poker智能ai辅助介绍(黑科技)外挂辅助挂辅助工具(确实有挂)-哔哩哔哩是一款...
黑科技好友!wpk专用辅助程序... 黑科技好友!wpk专用辅助程序(透视)扑克教程(2024已更新)(哔哩哔哩)1、wpk专用辅助程序a...