搜索文件命令还有which,whereis(不经常使用),locate 组合键解释: Ctrl+a : 光标移动到命令最前面; Ctrl+e:光标移到命令最后面; Ctrl+L:清屏 Ctrl+u:删除光标前面全部的命令 概念:find命令 就是用于搜索文件 命令格式: find 路径 参数 参数: -atime +n和-n :表示访问或执行时间大于或小于n天的文件。 -ctime +n和-n :表示写入、更改iNode属性(如更改全部者、权限或者连接)的时间大于或小于n天的文件。 -mtime +n和-n :表示写入时间大于或小于n天的文件,该参数用的最多。
find使用到的命令:node
- -type 经过文件类型查找文件 例: -type f 以文件类型找到
- -mtime 表示几天内 或者几天前的文件,mtime -1 一天内; mtime +10 10天前
- -size 表示文件字节选择列出来的文件 例:-size +10k 大于10k的文件。
- -o 和,例:-type f -o -mtime -1 查看以文件类型和小于一天的文件。
- -exec 推进后面的命令,例: find /root/ -type f -mmin -120 -exec ls -l {} \; 把前面的命令 以ls -l列出来。
find命令的使用,例:若是知道在哪一个目录下,而后知道文件名字,如何查找呢? find /etc/ -name "sshd_config"linux
[root@zhangzhen-01 ~]# find /etc/ -name "sshd_config" #在这里find是搜索,-name空格后面双引号跟文件全面查找以下
/etc/ssh/sshd_configbash
若是你只知道大概文件名,能够用模糊查找 find /etc/ -name "sshd※"ssh
[root@zhangzhen-01 ~]# find /etc/ -name "sshd*" #在这里,前面格式同样,双引号里面sshd后面跟的是“※号”,表示通配符,以sshd开头的文件所有列出来。
/etc/ssh/sshd_config
/etc/systemd/system/multi-user.target.wants/sshd.service
/etc/sysconfig/sshd
/etc/pam.d/sshdui
概念:-type filetype 表示经过文件类型查找文件。以下几种文件类型 d 表示该文件为目录; f 表示该文件为普通文件 l 表示该文件为连接文件 (如软连接 硬连接) b 表示该文件为块设备 c 表示该文件为串行端口设备文件 s 表示该文件为套接字文件 该命令格式以下: find /etc/ -type d -name "sshd*" #查找文件为目录的sshd*全部文件
概念:这个stat命令主要就是看最近访问(atime)、最近更改(mtime)、和最近改动的时间(ctime)建立时间的。
使用命令以下:spa
[root@zhangzhen-01 ~]# stat dior
文件:"dior"
大小:32 块:0 IO 块:4096 目录
设备:803h/2051d Inode:499801 硬连接:2
权限:(0755/drwxr-xr-x) Uid:( 0/ root) Gid:( 1001/ user1)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2018-03-29 00:31:52.739168672 +0800
最近更改:2018-03-28 22:44:38.990222665 +0800
最近改动:2018-03-29 00:31:40.627056046 +0800
建立时间:-.net
作个示例,搜索小于1天内,在/etc目录下,最近访问的块设备有哪些。code
[root@zhangzhen-01 ~]# find /etc/ -type b -atime -1
[root@zhangzhen-01 ~]# find /etc/ -type f -atime -1
/etc/resolv.conf
/etc/pki/tls/openssl.cnf
/etc/pki/nss-legacy/nss-rhel7.config
/etc/rpm/macros.dist
/etc/yum.repos.d/CentOS-Base.repo
/etc/yum.repos.d/CentOS-CR.repo
/etc/yum.repos.d/CentOS-Debuginfo.repo
/etc/yum.repos.d/CentOS-Media.repoblog在这里,find表示搜索, 空格 后面跟须要搜索的文件,空格 -type(表示经过文件类型查找文件) 空格 后面 b(表示块设备)空格 -atime(最近访问)-1 (小于一天,能够用“+”多少天之前的,“-”表示多少天之内的)
“-o” 表示或者,使用方法以下:ssl
[root@zhangzhen-01 ~]# find /etc/ -type f -o -mtime -1 -0 -name "*.com"
如何搜索硬连接,如何搜索iNode文件都有什么。
[root@zhangzhen-01 ~]# ln anaconda-ks.cfg /tmp/23.txt.heh #作个硬连接到/tmp下建立个23.txt.heh的文件
[root@zhangzhen-01 ~]# ls -l anaconda-ks.cfg #下面的内容就是硬连接的文件
-rw-------. 2 root root 6901 3月 27 22:40 anaconda-ks.cfg
[root@zhangzhen-01 ~]# ls -i /tmp/23.txt.heh #查看刚硬连接的iNode号
33574978 /tmp/23.txt.heh
[root@zhangzhen-01 ~]# find / -inum 33574978 #查看iNode号的文件都有哪些
/root/anaconda-ks.cfg
/tmp/23.txt.heh
如何用find查看2小时以内的文件
[root@zhangzhen-01 ~]# find /root/ -type f -mmin -120 **#-mmin后面跟分钟数
/root/.bash_history
/root/dior/1.txt
若是利用find把查看的文件直接ls -l出来,格式以下:
root@zhangzhen-01 ~]# find /root/ -type f -mmin -120 -exec ls -l {} \;
-rw-------. 1 root root 9759 3月 31 00:22 /root/.bash_history
-rw-r--r--. 1 root root 15 3月 30 23:39 /root/dior/1.txt注:-exec也是find的一种格式,后面跟你要对文件进行的命令, {} 花括号表示ls -l出来的内容, \;反斜杠+分号只是让他执行这个命令,推进出来。
如何利用find给以前建立的文件批量改后缀名呢,命令格式以下: -mmin
[root@zhangzhen-01 ~]# find /root/ -type f -mmin -300
/root/.bash_history
/root/dior/1.txt
[root@zhangzhen-01 ~]# find /root/ -type f -mmin -120 -exec mv {} {}.bak \;
[root@zhangzhen-01 ~]# find /root/ -type f -mmin -300
/root/dior/1.txt.bak
/root/.bash_history.bak注:第二个花括号表示所每个文件。
如何用find把大于10K的文件列出来。 -size +10k
[root@zhangzhen-01 ~]# find /root/ -type f -size +10k -exec ls -lh {} \;
-rwxr-xr-x. 2 root root 37K 8月 4 2017 /root/dior/login注:在这里,小于就用“-”号,后面跟单位字节。
概念:在linux里,命令有区分大小写。 后缀名可自定义,不过通常都是分类进行区别,方便你们查找。 参考文献:https://blog.csdn.net/fushaonian/article/details/72782651