命令findphp
命令语法:
find [路径][参数]html
命令描述
命令find是用来搜索文件。node
命令选项
-type 表示 文件类型
-name 表示 文件名
-o 表示 或 的意思
-mmin 表示分钟
-inum 表示查找一个文件的硬连接。
-exec <执行指令>:假设find指令的回传值为True,就执行该指令。
-size 文件大小
-atime +n/-n 表示访问或执行时间大于或小于n天的文件。
-ctime +n/-n 表示写入,更改inode属性(如更改全部者,权限或者连接)的时间大于或小于n天的文件。
-mtime +n/-n 表示写入时间大于或小于n天的文件,该参数用得最多。linux
- 文件的 access time(即atime) 是在读取文件或者执行文件时更改的。
指定名字 -neme shell
指定类型-type d f (-) l s c b 浏览器
#find /etc/ -name "sshd_config"bash
根据name的前半部分模糊搜索文件会列出与之相关的文件。 其语法: find 路径 -name "文件名的前半部分 less
#find /etc/ -name "sshd*"ssh
指定文件#find /etc/ -type d -name "sshd*" (d目录directory)spa
#find /etc/ -type f -name "sshd*" (f文件file)
根据文件的类型模糊搜索文件。 其语法: find 路径 -type 文件类型 "文件名的前半部分 * "
说明: 这里的 f 表示文件的类型。文件的类型有 - 普通文件,l 连接文件,b 块设备文件等等。。。固然也可使用find命令只指定类型不指定name搜索文件。 d f (-) l s c b
stat命令 是用来查看一个文件的具体信息,(文件名字、文件大小、所用的块、设备、inode、硬连接、权限)和三个atime(access) mtime(modify) ctime(change)
[root@cham2 ~]# ls 111 123 1_heard.txt 22.txt 2.txt 88_sorft.txt anaconda-ks.cfg.1 11.txt 12.txt 1_sorft 234 88_heard.txt 88.txt [root@cham2 ~]# stat 2.txt 文件:"2.txt" 大小:1008 块:8 IO 块:4096 普通文件 设备:803h/2051d Inode:16777669 硬连接:1 权限:(0700/-rwx------) Uid:( 0/ root) Gid:( 0/ root) 最近访问:2017-10-25 16:41:31.486026949 +0800 最近更改:2017-10-25 16:41:31.486026949 +0800 最近改动:2017-10-25 16:41:31.486026949 +0800 建立时间:-
atime=access访问时间 mtime=modify更改内容时间 ctime=change改动权限大小时间指的是除了内容的变化外 权限的变化 连接的变化 都算 等
#chmod 700 2.txt 改变了2.txt权限ctime(change)时间会变
echo命令 追加#echo "121212" >> 2.txt 从后面追加 mtime(modify)和ctime(change)都跟着变了
*知识点*改了文件的内容。那么ctime 必定会变。ctime文件记录着文件大小,时间,权限,全部者,所属组**
cat一次2.txt说明访问了。access=atime的时间就会变
用find查看一天之内的-1就是一天之内的,+1就是一天日后大于一天内的
#find /etc/ -type f -mtime -1 一天之内 ^C (file)
find /etc/ -type f -mtime +1 大于一天文件较多,不截图,相似-1
不能写=1
看一下一天之内/etc/发生过更改的文件,注意是文件file
还能够搜一天内的访问的文件
#find /etc/ -type f -atime -1 内容较多,不截图
还有#find /etc/ -type f -ctime -1
特殊用法
而且和或者
而且
或者o就是or内容太多,不截图
find搜索一个硬连接
语法# find / -inum 33575641
[root@cham2 ~]# ls -l total 16 -rw-rw-r-- 1 root root 135 Oct 25 17:44 11.txt drwxrwxr-- 3 root root 126 Oct 26 20:41 111 -rw-r--r-- 1 root root 65 Oct 25 17:20 12.txt drwxr-xr-x 2 root root 42 Oct 26 20:41 123 -rw-r--r-- 1 root root 0 Oct 25 17:31 1_heard.txt lrwxrwxrwx 1 root root 5 Oct 26 21:31 1_sorft -> 1.txt -rwx------ 1 root root 1062 Oct 27 14:36 2.txt -rw-r--r-- 1 root root 0 Oct 25 17:07 22.txt drwxrwxr-x 4 root user1 64 Oct 26 14:09 234 -rw-r--r-- 2 root root 0 Oct 26 21:33 88.txt -rw-r--r-- 2 root root 0 Oct 26 21:33 88_heard.txt lrwxrwxrwx 1 root root 6 Oct 26 21:34 88_sorft.txt -> 88.txt -rw-------. 1 root root 1422 Oct 19 07:00 anaconda-ks.cfg.1 [root@cham2 ~]# ln 1_heard.txt /tmp/1.txt.bak 建立一个硬连接到tmp下面去命名为1.txt.bak [root@cham2 ~]# ls -l 1_heard.txt 看一下 -rw-r--r-- 2 root root 0 Oct 25 17:31 1_heard.txt [root@cham2 ~]# ls -i 1_heard.txt ls -i看一下inode号 33575641 1_heard.txt [root@cham2 ~]# find / -inum 33575641 用find去查找 这个inode号 /root/1_heard.txt /tmp/1.txt.bak
查找 /root/ 500分钟之内的写入过的文件。
如图所示:
其中 -mmin表明分钟
mmin
# find /root/ -type f -mmin -500
[root@cham2 ~]# find /root/ -type f -mmin -500 /root/.bash_history.bak /root/2.txt.bak [root@cham2 ~]# ls -l /root/2.txt.bak -rwx------ 1 root root 1062 10月 27 14:36 /root/2.txt.bak [root@cham2 ~]#
find的同时直接把文件列出来
在查找 /root/ 500分钟之内的写入过的文件的同时把文件的详细信息列出来。
如图所示:
在上图命令的基础上增长了: -exec ls -l { } \
命令解析:
1.-exec<执行指令>:假设find指令的回传值为True,就执行该指令。
2.ls -l :显示文件的详细信息
3.{ } 表示find出来的文件的列表
# find /root/ -type f -mmin -500 -exec ls -l {} \;
[root@cham2 ~]# find /root/ -type f -mmin -500 -exec ls -l {} \; -rw-------. 1 root root 10116 10月 27 15:13 /root/.bash_history.bak -rwx------ 1 root root 1062 10月 27 14:36 /root/2.txt.bak
find 的出来后的文件更名字 或者拷贝一下
# find /root/ -type f -mmin -900 -exec mv {} {}.bak \;
[root@cham2 ~]# find /root/ -type f -mmin -900 -exec mv {} {}.bak \; [root@cham2 ~]# find /root/ -type f -mmin -900 /root/.bash_history.bak.bak /root/2.txt.bak.bak
查找/root/目录下小于10k的文件,并列出详细信息。
-exec
小于10K的
# find /root/ -type f -size -10 -exec ls -lh {} \;
[root@cham2 ~]# find /root/ -type f -size -10 -exec ls -lh {} \; -rw-r--r--. 1 root root 18 12月 29 2013 /root/.bash_logout -rw-r--r--. 1 root root 176 12月 29 2013 /root/.bash_profile -rw-r--r--. 1 root root 176 12月 29 2013 /root/.bashrc -rw-r--r--. 1 root root 100 12月 29 2013 /root/.cshrc -rw-r--r--. 1 root root 129 12月 29 2013 /root/.tcshrc -rw-r--r-- 1 root root 354 10月 19 12:20 /root/.ssh/known_hosts -rw------- 1 root root 1.7K 10月 18 23:58 /root/.ssh/id_rsa -rw-r--r-- 1 root root 392 10月 18 23:58 /root/.ssh/id_rsa.pub -rw------- 1 root root 789 10月 19 13:33 /root/.ssh/authorized_keys -rw-------. 1 root root 1.4K 10月 19 07:00 /root/anaconda-ks.cfg.1 -rw------- 1 root root 62 10月 24 13:35 /root/.lesshst -rw-r--r-- 1 root user1 0 10月 26 14:07 /root/234/chamlinux -rw-r--r-- 1 root root 0 10月 26 14:09 /root/234/chamlinux111 -rw-r--r-- 1 root root 195 10月 25 17:23 /root/111/12.txt -rw------- 1 root root 0 10月 25 17:19 /root/111/.12.txt.swp -rw------- 1 root root 0 10月 25 17:19 /root/111/.12.txt.swx -rw-r--r-- 1 root root 0 10月 25 17:20 /root/111/4913 -rw-r--r-- 1 root root 0 10月 25 17:20 /root/111/12.tx~ -rw-r--r-- 1 root root 0 10月 25 17:07 /root/22.txt -rw-rw-r-- 1 root root 135 10月 25 17:44 /root/11.txt -rw-r--r-- 1 root root 65 10月 25 17:20 /root/12.txt -rw-r--r-- 2 root root 0 10月 25 17:31 /root/1_heard.txt -rw-r--r-- 2 root root 0 10月 26 21:33 /root/88.txt -rw-r--r-- 2 root root 0 10月 26 21:33 /root/88_heard.txt -rwx------ 1 root root 1.1K 10月 27 14:36 /root/2.txt.bak.bak
大于10K的
[root@cham2 ~]# find /root/ -type f -size +10 -exec ls -lh {} \; -rw-r--r-- 1 root root 12K 10月 25 17:20 /root/111/12_txt.swp -rw------- 1 root root 12K 10月 25 17:02 /root/.1.txt.swp -rw-------. 1 root root 9.9K 10月 27 15:13 /root/.bash_history.bak.bak
大于10M同理
find的经常使用的用法
find :-type -mtime -mmin -size -o -exec -name
文件名后缀
在Linux下面命令或者文件是区分大小写的
文件名后缀
· .txt文件文件
· .zip压缩文件
· .tar.gz打包文件
· .conf配置文件
· .exe可执行文件
注: 在Linux系统中,文件的后缀名没有具体的意义,加或不加都无所谓。可是为了便于区分,咱们习惯在定义文件名时加一个后缀名。一个Linux文件能不能被执行,与他的第一栏的十个属性有关, 与文档名根本一点关系也没有。
在Linux下,使用预设的Ext2/Ext3文件系统时,针对文件的档名长度限制为:
单一文件或目录的最大允许文件名为 255 个字符;
包含完整路径名称及目录 (/) 之完整档名为 4096 个字符。
因为Linux在文字接口下的一些指令操做关系,通常来讲,你在设定Linux底下的文件名时, 最好能够避免一些特殊字符比较好!例如底下这些:
? > < ; & ! [ ] | \ ' " ` ( ) { } *
注: 由于这些符号在文字接口下,是有特殊意义的!另外,文件名的开头为小数点『.』时, 表明这个文件为『隐藏文件』!同时,因为指令下达当中,经常会使用到 -option 之类的选项, 因此最好也避免将文件档名的开头以 - 或 + 来命名 。