当前位置:首页> 正文

find命令与Linux文件扩展名-文件扩展名

命令find

用来查找搜索文件。

搜索文件相关命令:

  • which 从环境变量里的目录中去搜索
  • whereis(不常用) 从一个固定的库中搜索
  • locate(需要单独安装 yum install -y mlocate)
  • 查询时会从/var/lib/mlocate/mlocate.db中去查询,而/var/lib/mlocate/mlocate.db会在每天凌晨4点去更新,第一次使用时可以使用updatedb去更新库。
[root@centos01 ~]# locate 1234
locate: 无法执行 stat () `/var/lib/mlocate/mlocate.db': 没有那个文件或目录
[root@centos01 ~]# updatedb

find 命令使用

find /etc/ -name "sshd_config" # 查找etc下名字是sshd_config的文件或目录
find /etc/ -name "sshd*" # 模糊查找以sshd开始的文件或目录
find /etc/ -type d -name "sshd*" # 只搜索目录
find /etc/ -type f -name "sshd*" # 只搜索文件
# stat 文件名 # 查看文件的具体信息
[root@centos01 ~]# stat a.txt
文件:"a.txt"
大小:4865 块:16 IO 块:4096 普通文件
设备:803h/2051d Inode:67826381 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2018-09-14 09:18:16.795925149 +0800
最近更改:2018-09-14 09:18:13.364925250 +0800
最近改动:2018-09-14 09:18:13.364925250 +0800
创建时间:-
最近访问:查看文件内容信息时会记录
最近改动: 改权限等
最近更改:更改内容等,也会更改最近改动
# 切换当前系统环境语言
[root@centos01 ~]# LANG=en
[root@centos01 ~]# stat a.txt
File: 'a.txt'
Size: 4865 Blocks: 16 IO Block: 4096 regular file
Device: 803h/2051d Inode: 67826381 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2018-09-14 09:18:16.795925149 +0800
Modify: 2018-09-14 09:18:13.364925250 +0800
Change: 2018-09-14 09:18:13.364925250 +0800
Birth: -
# mtime 最小单位按天算
find / -type f -mtime -1 # 查找1天内更改的文件,+1表示1天以前的
find /etc/ -type f -o -mtime -1 # -o表示查询条件或,
# 即普通文件或者1天内更改的所有文件
find / -inum inode号 # 根据inode号查找文件
find / -type f -mmin -60 # 60分钟内的更改的文件
# 对查询出来的结果再针对每一条结果执行其他操作 -exec
find /root/ -type f -mtime -1 -name '*.log' -exec ls -l {} \;
# 对find出来的文件重命名添加.bak
find /tmp/ -type f -mtime -10 -exec mv {} {}.bak \;
# -size 根据文件大小条件进行查询
find /root/ -size -1k -exec ls -lh {} \;
# console终端常用快捷键
# 在没输入指令前
ctrl + l 清屏
ctrl + d 或 exit 或 logout 退出当前连接
# 输入指令后
ctrl + u 删除光标之前的所有字符串
ctrl + d 向后一个个字母删除
ctrl + e 光标移到命令行最后
ctrl + a 光标移到命令行行首

文件扩展名(后缀名)

文件扩展名在Linux系统中没有具体意义,加或者不加都无所谓。不过为了方便区分和管理,通常还是会以适当的扩展名来表示该文件是什么类型的。

find命令与Linux文件扩展名

展开全文阅读

相关内容