linux学习第十篇:find命令,文件名后缀

find命令


find命令用于查找文件系统中的指定文件 其命令格式为  
find 要查找的路径 -name  查找文件名 

例如  
find . -name 1.txt                 // 在当前目录及其子目录下查找文件 1.txt  


find /tmp/ -name 1.txt         //在 /tmp 目录及其子目录下查找文件 1.txt  


find  /etc/    -type d  -name  test   //在etc目录及其子目录下查找名称为test的目录


find  /etc/    -type  f   -name  test   //在etc目录及其子目录下查找名称为test的文件

  //类型有  d(目录)f(文件)l(软连接文件)s(socket)c(字符串设备文件)b(块设备文件)


stat命令:查看文件的具体信息


最近访问:atime

最近更改:更改的是文件的内容 ---mtime

最近改动:权限,文件内容,inode更改时间会改变 ,mtime改变ctime也会改变,ctime改变mtime不一定改变--ctime


find   /etc/    -type  f   -mtime  -1  //在etc下查找1天以内更改的文件。+1即为大于1天

 //若为atime即为查找1天以内访问的文件。

 //若为ctime即为查找1天以内改动的文件。

find   /etc/    -type  f   -mtime  -1  -name test     //在etc下查找1天以内更改的文件,并且名称为test。


find   /etc/    -type  f    -o    -mtime  -1   -o     -name test     //在etc下查找1天以内更改的文件或者名称为test。


find   /etc/    -type  f   -mmin  -60     //在etc下查找60分钟以内更改的文件。


find /root/  -type f -mmin -120 -exec ls -l {} \;    //列出root下120分钟内更改的文件的信息

[root@xie-02 ~]# find /root/  -type f -mmin -120 -exec ls -l {} \;   //{}表示列出的文件的其中之一,对每个文件都使用ls -l
-rw-r--r--. 1 root root 0 10月 26 14:53 /root/2.txt


find /root/  -type f -mmin -120 -exec mv {} {}.bak  \;  //将root下120分钟内更改的文件重命名加上.bak。
[root@xie-02 ~]# find /root/  -type f -mmin -120 -exec ls -l {} \;
-rw-r--r--. 1 root root 0 10月 26 14:53 /root/2.txt
-rw-r--r--. 1 root root 0 10月 26 14:54 /root/12.txt
-rw-r--r--. 1 root root 0 10月 26 14:55 /root/123.txt
[root@xie-02 ~]# find /root/  -type f -mmin -120 -exec mv {} {}.bak  \;
[root@xie-02 ~]# find /root/  -type f -mmin -120 -exec ls -l {} \;
-rw-r--r--. 1 root root 0 10月 26 14:53 /root/2.txt.bak
-rw-r--r--. 1 root root 0 10月 26 14:54 /root/12.txt.bak
-rw-r--r--. 1 root root 0 10月 26 14:55 /root/123.txt.bak

find  /root/  -type f  -size  -1k  -exec  ls -lh {}  \;   //列出 root下文件大小小于1k的文件具体信息。也可以为M

[root@xie-02 ~]# find /root/ -type f -size -1k -exec ls -lh {} \; 
-rwx------. 2 root root 0 10月 25 12:14 /root/1.txt
-rw-r--r--. 1 root root 0 10月 25 15:04 /root/111/1.txt
-rw-r--r--. 1 root root 0 10月 26 14:53 /root/2.txt.bak
-rw-r--r--. 1 root root 0 10月 26 14:54 /root/12.txt.bak
-rw-r--r--. 1 root root 0 10月 26 14:55 /root/123.txt.bak

find  /   -inum   33583365             //用于查找inode号为33583365的文件,用于查找硬链接文件


了解:命令locate也可对文件进行搜索,可用yum install -y mlocate安装,再用updatedh生成数据库。

            locate test //对包含有test名称的目录和文件进行搜索列出。(不精准)





文件名后缀


linux下创建文件可以自定义文件的后缀,但并不能代表这个文件的类型,自定义文件后缀是为了方便文件的区别。


LANG=en    // 将中文显示成英文

LANG=zh_CN.UTF-8   // 将英文显示成中文






额外小知识

stat 查看文件信息
ctrl l 命令首行
ctrl c 取消
ctrl u 删除光标前的
ctrl d 删除后边一位
ctrl a 光标最前边
ctrl e 光标最后边
ctrl k 删除光标后的






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值