博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
find命令用法
阅读量:6868 次
发布时间:2019-06-26

本文共 4841 字,大约阅读时间需要 16 分钟。

hot3.png

stat命令

atime mtime ctime

stat命令用来查看文件或目录的详细信息,用法为stat 文件名

[root@localhost ~]# stat /tmp/1  文件:"/tmp/1"  大小:6         	块:0          IO 块:4096   目录设备:803h/2051d	Inode:620180      硬链接:2权限:(0755/drwxr-xr-x)  Uid:(    0/    root)   Gid:(    0/    root)环境:unconfined_u:object_r:user_tmp_t:s0最近访问:2018-06-09 08:18:49.367936994 +0800最近更改:2018-06-09 08:18:49.367936994 +0800最近改动:2018-06-09 08:18:49.367936994 +0800创建时间:-

使用这个命令可以看到里面有三个时间点,Access ,Modify,Change 改成英文看比较直观

[root@localhost ~]# LANG=en[root@localhost ~]# !statstat /tmp/1  File: '/tmp/1'  Size: 6         	Blocks: 0          IO Block: 4096   directoryDevice: 803h/2051d	Inode: 620180      Links: 2Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)Context: unconfined_u:object_r:user_tmp_t:s0Access: 2018-06-09 08:18:49.367936994 +0800Modify: 2018-06-09 08:18:49.367936994 +0800Change: 2018-06-09 08:18:49.367936994 +0800 Birth: -

这三个时间点可以分别表示为,atime , mtime ,ctime 当对该文件访问后,atime 会改变;改变了文件内容后mtime ,ctime 会一起改变,改变了文件的iNode属性后(例如权限,链接,属主属组等信息)会改变它的ctime

[root@localhost ~]# stat /tmp/2.txt   文件:"/tmp/2.txt"  大小:0         	块:0          IO 块:4096   普通空文件设备:803h/2051d	Inode:100663426   硬链接:1权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)环境:unconfined_u:object_r:user_tmp_t:s0最近访问:2018-06-09 08:19:01.604936912 +0800最近更改:2018-06-09 08:19:01.604936912 +0800最近改动:2018-06-09 08:19:01.604936912 +0800创建时间:-[root@localhost ~]# echo "1212121212121212" >> /tmp/2.txt [root@localhost ~]# !statstat /tmp/2.txt   文件:"/tmp/2.txt"  大小:17        	块:8          IO 块:4096   普通文件设备:803h/2051d	Inode:100663426   硬链接:1权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)环境:unconfined_u:object_r:user_tmp_t:s0最近访问:2018-06-09 08:19:01.604936912 +0800最近更改:2018-06-09 08:38:19.209929176 +0800最近改动:2018-06-09 08:38:19.209929176 +0800创建时间:-

在这里我们可以看到,当改变了文件内容后,Mtime和ctime备改变了 ,atime没有改变

最近访问:2018-06-09 08:19:01.604936912 +0800最近更改:2018-06-09 08:38:19.209929176 +0800最近改动:2018-06-09 08:38:19.209929176 +0800创建时间:-[root@localhost ~]# cat /tmp/2.txt 1212121212121212[root@localhost ~]# !statstat /tmp/2.txt   文件:"/tmp/2.txt"  大小:17        	块:8          IO 块:4096   普通文件设备:803h/2051d	Inode:100663426   硬链接:1权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)环境:unconfined_u:object_r:user_tmp_t:s0最近访问:2018-06-09 08:40:11.105928429 +0800最近更改:2018-06-09 08:38:19.209929176 +0800最近改动:2018-06-09 08:38:19.209929176 +0800创建时间:-

上面代码可以看到,访问文件之后被改变的只有atime 。

最近访问:2018-06-09 08:40:11.105928429 +0800最近更改:2018-06-09 08:38:19.209929176 +0800最近改动:2018-06-09 08:38:19.209929176 +0800创建时间:-[root@localhost ~]# chmod 666 /tmp/2.txt [root@localhost ~]# !statstat /tmp/2.txt   文件:"/tmp/2.txt"  大小:17        	块:8          IO 块:4096   普通文件设备:803h/2051d	Inode:100663426   硬链接:1权限:(0666/-rw-rw-rw-)  Uid:(    0/    root)   Gid:(    0/    root)环境:unconfined_u:object_r:user_tmp_t:s0最近访问:2018-06-09 08:40:11.105928429 +0800最近更改:2018-06-09 08:38:19.209929176 +0800最近改动:2018-06-09 08:42:06.055927660 +0800

而改变文件的权限后,只有ctime改变,其他不变。

find 命令

上面讲这些是为了这个find命令的一个用法做的铺垫。 find命令是一个搜索命令,它的用途特别多,命令格式为: find <指定目录> <指定条件> <指定动作>

  • 指定目录 :可以指定目录,如果不指定则默认为当前目录下搜索
  • 指定条件:这个选项比较丰富了
  1. 指定文件类型 -type 文件类型
  2. 指定更改时间 -mtime +1/-1(更改时间为一天以前的/更改时间为一天以内的)
  3. -mmin 100 (更改时间100分钟以内的);
  4. -name "*.tar" (文件名中有.tar字符的)
  • 指定动作:将查找出的文件做什么处理,例如:find -type f -mtime -1 -exec lsattr {} ; (找出更改时间在1天以内的文件并显示它的隐藏权限)
[root@localhost ~]# find /tmp/ -type f -mtime -1 -exec ls -l {} \;-rw-rw-rw-. 1 root root 55 6月   9 09:09 /tmp/2.txt[root@localhost ~]# find /tmp/ -type f -mtime -1 -exec lsattr {} \;---------------- /tmp/2.txt

还有一个查找硬链接文件,当我们知道一个文件做了硬链接了,想找到硬链接文件可以使用:find 目录 -inum inode号 来查找

[root@localhost ~]# ln /tmp/2.txt /media/567.txt[root@localhost ~]# ls -li /tmp/2.txt 100663426 -rw-rw-rw-. 2 root root 55 6月   9 09:09 /tmp/2.txt[root@localhost ~]# find / -inum 100663426 /tmp/2.txt/media/567.txt

find命令用法多样化,而且很强大。

lacate whereis命令

首先安装mlocate包才能运行locate命令,

[root@test-01 ~]# yum install -y mlocate

并且首次使用会报错,因为系统没有生成mlocate.db这个库,可以使用updatedb命令 立即生成,生成库文件会占用较多资源,如果服务器在跑业务,最好不要执行这条命令,locate命令也是模糊查找,在搜索到的列表中,不管是目录还是文件,只要包含我们所查找的字符,就会被列出来,所以locate不适合精确查找。

[root@localhost ~]# locate /lic/home/lic/home/lic/.bash_history/home/lic/.bash_logout/home/lic/.bash_profile/home/lic/.bashrc/usr/share/doc/ivtv-firmware-20080701/license-end-user.txt/usr/share/doc/ivtv-firmware-20080701/license-oemihvisv.txt/var/spool/mail/lic

whereis命令

whereis命令也不常用,格式为whereis_ -参数 filename_ 参数及含义如下:

  • -b: 只查找二进制文件
  • -m:只查找帮助文件(在man目录下的文件)
  • -s:只查找源代码文件
[root@test-01 ~]# whereis lsls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

whereis命令类似于模糊查找,如上所示,运行whereis ls 只要带有ls字符,就会被列出来

[root@localhost ~]# whereis lsls: /usr/bin/ls /usr/share/man/man1/ls.1.gz[root@localhost ~]# whereis -m lsls: /usr/share/man/man1/ls.1.gz

文件后缀名

在Linux系统中,文件后缀名并不严谨,常常没有实际意义,就是因为惯例 ,大家为了方便管理,会将一类的文件给定统一的后缀名。

转载于:https://my.oschina.net/u/3731306/blog/1827198

你可能感兴趣的文章
SQL SERVER存储过程中如何使用事务与try catch
查看>>
没什么不可能:剿灭Windows下的29个烦恼
查看>>
String,StringBuffer,StringBuilder的整理
查看>>
mysql 字符截取 实列
查看>>
部署mysql高可用、读写分离集群
查看>>
jquery中下拉多选插件jquery.multiSelect的使用
查看>>
梦想与现实,你会选择什么——一个电子爱好者的迷茫
查看>>
用rabbitMQ实现生产者消费者
查看>>
GRADLE遇见“设备未就绪”
查看>>
正则表达式实现——匹配括号中的A 以及 匹配非括号中的A
查看>>
golang锁sync.Mutex
查看>>
定义自己的JSTL标签库
查看>>
JAVA 相关
查看>>
PowerDesigner导出数据结构到word
查看>>
性能调优--永远超乎想象
查看>>
zabbix监控mysql
查看>>
cisco路由器上做端口映射
查看>>
Lua 和 C/C++ 互相调用实例分析
查看>>
初见:存储过程 调用方法
查看>>
centos 6.7 安装注意事项
查看>>