find命令、文件名后缀
1. 一些命令行的快捷方式:
ctrl l 清屏 ctrl d 退出终端 ctrl c 跳到下一行,不执行 ctrl u 清除一行 ctrl e end,光标移到最后 ctrl a 光标移到最开始 which 搜索命令的路径,是从PATH环境变量里面去找的 whereis 也是一个搜索命令,但是不常用,搜索得不全
2. locate 查找命令
yum install -y mlocate #安装mlocate updatedb #安装mlocate后先要更新数据库 locate [文件名] #搜索文件,但是用的不多
3.stat 查看文件的三个时间节点
[root@localhost ~]# stat 22.txt File: '22.txt' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 803h/2051d Inode: 16814123 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:admin_home_t:s0 Access: 2017-12-21 17:35:02.503309203 +0800 Modify: 2017-12-21 17:35:02.503309203 +0800 Change: 2017-12-21 17:35:02.503309203 +0800
atime:文件的最近一次访问时间,比如cat读取一个文件时
ctime:当文件的状态改变时,会更新这个时间,一般为修改文件权限或者文件名
mtime:当文件的内容数据改变时,会更新这个时间,指文件的内容发生改变
一、find命令
find -name -type -mtime -mmin -o -exec -size
1. find -name 指定文件名搜索
1.[root@localhost ~]# find /etc/ -name "sshd_config" #搜索/etc/目录下得sshd_config文件 /etc/ssh/sshd_config 2.[root@localhost ~]# 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
2. find -type 指定文件的类型,-d 目录、-f 文件、-l 软链接、 -s soket文件、-c字符串文件 、-b块文件
[root@localhost ~]# find /dev/ -type b #-type b,指定文件类型为b,搜索/dev/目录下的块文件 /dev/sr0 /dev/sda3 /dev/sda2 /dev/sda1 /dev/sda
3. find -mtime 按照时间查找文件,也可以使用atime 、ctime
[root@localhost ~]# find /etc/ -mtime -1 -mtime ,按照mtime更新的时间,-1 为减1,意思是一天以内,如果是+1,那么就是大于1天 /etc/ /etc/resolv.conf /etc/cron.daily /etc/group /etc/gshadow
4. find -o 或者的意思,多个条件连在一起,满足其中一个即可
[root@localhost ~]# find /etc/ -type d -o -ctime -1 -o -name "*.comf" #-o表示或者的意思,只要满足其中一个条件即可 /etc/ /etc/resolv.conf /etc/grub.d /etc/pki /etc/pki/rpm-gpg /etc/pki/ca-trust /etc/pki/ca-trust/extracted /etc/pki/ca-trust/extracted/java /etc/pki/ca-trust/extracted/openssl /etc/pki/ca-trust/extracted/pem /etc/pki/ca-trust/source /etc/pki/ca-trust/source/anchors /etc/pki/ca-trust/source/blacklis
5. find -inum 按照inode号进行寻找,可以寻找文件的硬链接
[root@localhost ~]# find / -inum 16813925 #指定inode,可以查到所有使用相同inode的文件 /root/11.txt /root/11_hard.txt /tmp/11.txt.bak
6. find -mmin 按照分钟查找文件,60分钟就是一个小时
[root@localhost ~]# find /root/ -type f -mmin -120 #mmin 时间单位为分钟,-120就是120分钟以内修改的文件,120分钟就是两个小时2 /root/.bash_history
7. find -exec 后面可以接命令,对寻找到的文件进行处理
[root@localhost ~]# find /root/ -type f -mtime -1 -exec ls -l {} \; -rw-------. 1 root root 6466 Dec 22 17:38 /root/.bash_history -rw-r--r--. 3 root root 924 Dec 22 09:27 /root/11.txt -rw-r--r--. 3 root root 924 Dec 22 09:27 /root/11_hard.txt
这个命令的意思是寻找root目录(-type f)下,300分钟(-mmin -300)以内更改的文件,并使用ls -l列出来,-exec是find命令的一种用法,ls -l {}是列出找到的文件,\反斜杠是转义字符
这个命令的意思是寻找root目录(-type f)下,150分钟(-mmin -300)以内更改的文件,并将文件名加一个后缀hjk
8. find -size 根据文件的大小寻找文件,k表示kb,M表示MB,M使用大写
[root@localhost ~]# find /root/ -size +5k -exec ls -lh {} \; #-size 指定文件大小 ,+5k 大于5kb的文件,并用ls -lh列出来 -rw-------. 1 root root 6.4K Dec 22 17:38 /root/.bash_history
二、文件名后缀
linux下是区分大小写的
linux文件也是有后缀名的,但是不能代表一个文件的类型。
把相同的文件定义一个相同的后缀名,比较方便查看
date #查看系统时间 echo $LANG #查看系统语言
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
