一、find命令

Linux系统中的 find 命令在查找文件时非常有用而且方便。它可以根据不同的条件来查找文件,例如权限、拥有者、修改日期/时间、文件大小等等。在这篇文章中,我们将学习如何使用 find 命令以及它所提供的选项来查找文件。

列出当前目录和子目录下的所有文件

[root@davery ~]# find
.
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./.ssh

搜索所有文件、目录:find /etc/ -name "xxx*"

root@davery ~]# find /etc/ -name "ssh*"
/etc/ssh
/etc/ssh/sshd_config
/etc/ssh/ssh_config
/etc/ssh/ssh_host_rsa_key
/etc/ssh/ssh_host_rsa_key.pub
/etc/ssh/ssh_host_ecdsa_key
/etc/ssh/ssh_host_ecdsa_key.pub
[root@davery ~]#

搜索目录,例子:find /etc/ -type d -name "xxx"

[root@davery ~]# find /etc/ -type d -name "ssh"
/etc/ssh
/etc/selinux/targeted/active/modules/100/ssh
[root@davery ~]#

搜索文件,例子:find /etc/ -type f -name "xxx"

[root@davery ~]# find -type f -name "*"
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./.ssh/known_hosts
./.bash_history
./anaconda-ks.cfg.01
./anaconda-ks.cfg.1

根据文件类型搜索文件

[root@davery ~]# find /etc/ -type l

[root@davery ~]# find /etc/ -type d

[root@davery ~]# find /etc/ -type b

[root@davery ~]# find /etc/ -type c

查看文件具体信息,stat 1.txt

[root@davery ~]# ls
1.txt anaconda-ks.cfg.01 anaconda-ks.cfg.1 davery make uear1 user1
[root@davery ~]#
[root@davery ~]#
[root@davery ~]# stat 1.txt
文件:"1.txt"
大小:6 块:0 IO 块:4096 目录
设备:803h/2051d Inode:652696 硬链接:2
权限:(0755/drwxr-xr-x) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2018-03-30 21:57:22.470173086 +0800     Access: -atime
最近更改:2018-03-29 00:12:37.656441521 +0800      Modify: -mtime
最近改动:2018-03-29 00:17:05.797933042 +0800      Change:-ctime
创建时间:-                                                                     Birth
[root@davery ~]#

查看/etc里面1天内更改的信息

[root@davery ~]# find /etc/ type f -mtime -1
/etc/
/etc/resolv.conf
/etc/cron.daily
/etc/group
/etc/gshadow
[root@davery ~]#

查看/etc里面60分钟内更改的信息

[root@davery ~]# find /etc/ -type f -mmin -60
/etc/resolv.conf
/etc/group
/etc/gshadow
[root@davery ~]#

查找大于1000k文件

[root@davery ~]# [root@davery ~]# find /etc/ -type f -size +1000k
/etc/udev/hwdb.bin
/etc/selinux/targeted/active/policy.kern
/etc/selinux/targeted/contexts/files/file_contexts.bin
/etc/selinux/targeted/policy/policy.30
[root@davery ~]#

查找大于1000k文件并显示大小

[root@davery ~]# find /etc/ -type f -size +1000k -exec ls -lh {} \;
-r--r--r--. 1 root root 7.2M 3月 23 06:09 /etc/udev/hwdb.bin
-rw-r--r--. 1 root root 3.6M 8月 6 2017 /etc/selinux/targeted/active/policy.kern
-rw-r--r--. 1 root root 1.4M 8月 6 2017 /etc/selinux/targeted/contexts/files/file_contexts.bin
-rw-r--r--. 1 root root 3.6M 8月 6 2017 /etc/selinux/targeted/policy/policy.30
[root@davery ~]#

二、文件名后缀

需要区分大小写

[root@davery ~]# ls
1.txt anaconda-ks.cfg.01 anaconda-ks.cfg.1 davery make uear1 user1
[root@davery ~]#
[root@davery ~]# Ls
-bash: Ls: 未找到命令
[root@davery ~]#

 

最新文章

  1. 数据库开发基础-SQl Server 主键、外键、子查询(嵌套查询)
  2. lnmp环境下载安装包
  3. 51nod 1290 Counting Diff Pairs 莫队 + bit
  4. mybaties中在xml中map添加一个list中的判断
  5. 部分具有统计功能的TSQL语句(例如DBCC语句,全局函数,系统存储过程)
  6. Centos6.7安装Apache2.4+Mysql5.6+Apache2.4
  7. zend studio 12.0 怎么汉化?
  8. 关于在线查看相关开源源码的网站,包括Android源码
  9. Python第一个入门程序
  10. 使用IDEA动态调试smali代码
  11. 日期格式化{0:yyyy-MM-dd HH:mm:ss.fff}和{0:yyyy-MM-dd hh:mm:ss.fff}的区别
  12. jquery 分页控件1
  13. mac 配置快捷键快速锁屏
  14. android开发之-查看、编辑手机sqlite数据库文件-实测
  15. 仿QQ空间和微信朋友圈,高解耦高复用高灵活
  16. Python 处理时间的模块
  17. Java 8 日期时间 API
  18. vCenter简单查看多少虚拟机在开机状态和一共多少虚拟机
  19. 宝塔Linux面板安装Redis
  20. 安卓修改开机logo和开机动画的方法

热门文章

  1. python3中的raise使用
  2. photoshop下载(ps)
  3. char **argv 与char *argv[]
  4. js中的跨域
  5. 201771010135杨蓉庆《面向对象程序设计(java)》第二周学习总结
  6. 新建文件的UID和GID
  7. 吴裕雄--天生自然TensorFlow2教程:链式法则
  8. java_1:为什么我一搞PHP的要转JAVA
  9. 高级T-SQL进阶系列 (一)【下篇】:使用 CROSS JOIN 介绍高级T-SQL
  10. problem :无法显示activemq的管理界面