前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >linux学习第十篇:find命令,文件名后缀

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

作者头像
用户1215343
发布2018-02-05 17:06:41
2K0
发布2018-02-05 17:06:41
举报
文章被收录于专栏:linux运维学习linux运维学习

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分钟内更改的文件的信息

代码语言:javascript
复制
[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。

代码语言:javascript
复制
[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

代码语言:javascript
复制
[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 删除光标后的

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年10月26日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档