用来查找搜索文件。node
搜索文件相关命令:centos
[root@centos01 ~]# locate 1234 locate: 没法执行 stat () `/var/lib/mlocate/mlocate.db': 没有那个文件或目录 [root@centos01 ~]# updatedb
find 命令使用ssh
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系统中没有具体意义,加或者不加都无所谓。不过为了方便区分和管理,一般仍是会以适当的扩展名来表示该文件是什么类型的。命令行