find命令、文件名后缀

[TOC]

2.23 find命令(上)(中)(下)

which whereis

一些搜索的命令

[root@mylinux ~]# which ls
alias ls='ls --color=auto'
    /usr/bin/ls
[root@mylinux ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

安装使用locate

[root@mylinux ~]# yum install -y mlocate
[root@mylinux ~]# locate ls
locate: 无法执行 stat () `/var/lib/mlocate/mlocate.db': 没有那个文件或目录 (没有文件路径数据库)
[root@mylinux ~]# updatedb (每天自动生成,这里手动生成)
[root@mylinux ~]# locate 123
/root/123 (查找123目录)
/usr/lib/golang/test/fixedbugs/bug123.go
/usr/lib/golang/test/fixedbugs/issue12347.go
/usr/lib/modules/3.10.0-693.el7.x86_64/kernel/drivers/media/dvb-frontends/cx24123.ko.xz
/usr/lib64/gconv/IBM1123.so
/usr/share/man/man1/perl5123delta.1.gz
/usr/share/perl5/pod/perl5123delta.pod

技巧:Ctrl + u可以把该行输入的所有命令清空
Ctrl + a把光标移动到最前面
Ctrl + e把光标移动到最后面

find基本用法

[root@mylinux ~]# find /etc/ -name "sshd_config" (在/etc/目录下寻找名字叫sshd_config的文件或者目录)
/etc/ssh/sshd_config

[root@mylinux ~]# find /etc/ -name "sshd*" (在/etc/目录下寻找名字前缀是sshd的文件或者目录,其实就是模糊搜索)
/etc/ssh/sshd_config
/etc/systemd/system/multi-user.target.wants/sshd.service
/etc/sysconfig/sshd
/etc/pam.d/sshd

[root@mylinux ~]# find /etc/ -type d -name "sshd*" (指定只要目录)

[root@mylinux ~]# find /etc/ -type f -name "sshd*" (指定文件和目录都显示,l为软链接文件,b为block文件一般在/dev/下)
/etc/ssh/sshd_config
/etc/sysconfig/sshd
/etc/pam.d/sshd

stata查看文件详情,详解三个time

[root@mylinux ~]# stat anaconda-ks.cfg 
  文件:"anaconda-ks.cfg"
  大小:1418       块:8          IO 块:4096   普通文件
设备:802h/2050d   Inode:33574978    硬链接:1
权限:(0600/-rw-------)  Uid:(    0/    root)   Gid:(    0/    root)
环境:system_u:object_r:admin_home_t:s0
最近访问:2017-12-23 10:34:56.694021406 +0800
最近更改:2017-12-12 23:42:39.669873370 +0800 (更改文件内容的时间)
最近改动:2017-12-12 23:42:39.669873370 +0800 (改动inum的时间)
创建时间:-
find的 -mtime是文件最近改动的时间,即是文件内容改动
    -atime是最近访问时间
-ctime是最近改动时间,是改动如权限一类文件信息,而不是文件内容


查看一天内发生更改的文件
[root@mylinux ~]# find /etc/ -type f -mtime -1
/etc/resolv.conf
/etc/resolv.conf.save

[root@mylinux ~]# find /etc/ -type f  -mtime -1 -o -name "*.conf" (-o表示或者)

通过inum查找硬链接文件

[root@mylinux ~]# mkdir 1
[root@mylinux ~]# touch 1.txt
[root@mylinux ~]# ln 1.txt 1/1.txt
[root@mylinux ~]# ls -l 1.txt 
-rw-r--r--. 2 root root 0 12月 24 14:23 1.txt
[root@mylinux ~]# ls -i 1.txt 
33575016 1.txt
[root@mylinux ~]# find / -inum 33575016
/root/1/1.txt
/root/1.txt

查找一小时以内的更改过的文件
[root@mylinux ~]# find /root/ -type f -mmin -60
/root/1/1.txt
/root/1.txt
查看并用ls -l的方式展现
[root@mylinux ~]# find /root/ -type f -mmin -60 -exec ls -l {} \;
-rw-r--r--. 2 root root 0 12月 24 14:23 /root/1/1.txt
-rw-r--r--. 2 root root 0 12月 24 14:23 /root/1.txt
更改找到文件或文件夹名称
[root@mylinux ~]# find /root/ -type f -mmin -60 -exec mv {} {}.bak \;
[root@mylinux ~]# find /root/ -type f -mmin -60 
/root/1/1.txt.bak
/root/1.txt.bak
查找小于10k的文件
[root@mylinux ~]# find /root/ -type f -size -10k -exec ls -lh {} \;

226 文件名后缀

Linux下可以自由定义文件后缀名,不存在指定的程序对指定后缀名文件打开,不像Windows。
类似Linux下的.conf文件都是一种配置文件,但是这只是约定俗成的。

    原文作者:强出头
    原文地址: https://www.jianshu.com/p/2a0633392803
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞