stat命令用来查看文件或目录的详细信息,用法为stat 文件名node
[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 改为英文看比较直观bash
[root@localhost ~]# LANG=en [root@localhost ~]# !stat stat /tmp/1 File: '/tmp/1' Size: 6 Blocks: 0 IO Block: 4096 directory Device: 803h/2051d Inode: 620180 Links: 2 Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:user_tmp_t:s0 Access: 2018-06-09 08:18:49.367936994 +0800 Modify: 2018-06-09 08:18:49.367936994 +0800 Change: 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 ~]# !stat stat /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没有改变code
最近访问: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 ~]# !stat stat /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 ~]# !stat stat /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改变,其余不变。test
上面讲这些是为了这个find命令的一个用法作的铺垫。 find命令是一个搜索命令,它的用途特别多,命令格式为: find <指定目录> <指定条件> <指定动做>object
[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号 来查找date
[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命令用法多样化,并且很强大。file
首先安装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_ -参数 filename_ 参数及含义以下:
[root@test-01 ~]# whereis ls ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
whereis命令相似于模糊查找,如上所示,运行whereis ls 只要带有ls字符,就会被列出来
[root@localhost ~]# whereis ls ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz [root@localhost ~]# whereis -m ls ls: /usr/share/man/man1/ls.1.gz
在Linux系统中,文件后缀名并不严谨,经常没有实际意义,就是由于惯例 ,你们为了方便管理,会将一类的文件给定统一的后缀名。