Day10 find命令、文件名后缀

stat 命令

  • 用于查看文件的具体信息

示例:

[root@centos001 ~]# ls
111  22.txt  2.txt  aling       anaconda-ks.cfg.1  ls2  //随便选择一个文件
123  234     3.txt  aminglinux  dir3               yum.log
[root@centos001 ~]# stat 2.txt             //用stat列出其文件属性
  文件:"2.txt"
  大小:0         	块:0          IO 块:4096   普通空文件
设备:fd00h/64768d	Inode:33575023    硬链接:1
权限:(0664/-rw-rw-r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2018-06-8 10:18:17.839439736 +0800         //这里可以看到文件的信息   atime
最近更改:2018-06-8 09:58:25.036568990 +0800       //ctime
最近改动:2018-06-8 10:17:57.282645569 +0800      //mtime
创建时间:-     

find命令

  • 用来搜索的其他命令:which 、whereis、locate(需要yum安装并用updatedb生成)
  • 几个常用快捷键
CTRL+C //结束(终止)当前命令
CTRL+D //退出当前终端
CTRL+Z  //暂停当前进程
CTRL+L  //清屏
CTRL+A //移动光标到最前
CTRL+E //移动光标到最后
CTRL+U //删除光标前的字符
常用find命令
  • -name filename:直接查找该文件名的文件

    示例:

[root@centos001 ~]# find /etc/ -name "sshd_config"   //在etc目录下搜索一个已知名字的文件
/etc/ssh/sshd_config
[root@centos001 ~]# find /etc/ -name "sshd*"        //模糊搜索 用“*”代替不知道的名称
/etc/ssh/sshd_config
/etc/systemd/system/multi-user.target.wants/sshd.service
/etc/sysconfig/sshd
/etc/pam.d/sshd
  • -type filetype:通过文件类型(如:f.b.c.d.l.s等)查找文件

    示例:

[root@centos001 ~]# find /etc/ -type l       //查找一个软链接文件
[root@centos001 ~]# ls -l /etc/rc1.d/      //选择一个路径查看其文件类型
总用量 0
lrwxrwxrwx. 1 root root 20 4月  29 18:55 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx. 1 root root 17 4月  29 18:55 K90network -> ../init.d/network
  • -atime +n/-n:查找访问或执行时间大于或小于n的文件
  • -ctime +n/-n:查找写入或更改inode属性的时间大于或小于n的文件

示例:

[root@centos001 ~]# find /etc/ -type f -ctime -1  //查找一个在一天内更改过inode属性的文件
/etc/resolv.conf
/etc/sysconfig/network-scripts/.ifcfg-en.swp
/etc/sysconfig/network-scripts/ifcfg-ens33
/etc/tuned/active_profile
  • -mtime +n/-n:查找写入时间大于或小于n的文件

示例:

[root@centos001 ~]# find /etc/ -type f -mtime -1 //在目录etc下查找写入时间在一天内的文件  切时间前只能用用加减号
/etc/resolv.conf                                                         
/etc/sysconfig/network-scripts/.ifcfg-en.swp
/etc/sysconfig/network-scripts/ifcfg-ens33
/etc/tuned/active_profile
  • -o:或者选项 有两者其中之一

示例:

[root@centos001 ~]# find /etc/ -type f -o -mtime -1 -o -name “*.conf”  //查找一个 etc目录下一天以内或者叫有conf结尾的文件
  • -inum:查找一个文件的inode号

示例:

[root@centos001 ~]# ln ls2  /tmp/5.txt.bak   //创建一个文件ls2的硬链接
[root@centos001 ~]# ls -l ls2                            //查看文件属性
-rw-r--r--. 2 root root 0 5月 25 02:55 ls2    //用户前面的2表示 硬链接已经创建成功
[root@centos001 ~]# ls -i ls2              //查看文件的inode号
33574978 ls2
[root@centos001 ~]# find / -inum 33574978          //查询有这个inode号的文件 。就能找到一个文件的硬链接位置
/root/ls2
/tmp/5.txt.bak
  • -mmin+n/-n:查找大于或小于n分钟的文件

示例:

[root@centos001 ~]# find /etc/ -type f -mmin -300        //查找5小时内的文件
/etc/resolv.conf
  • -exec: 在查找文件时列出文件 **语法:-exec ls -l {} ;**一定要写正确比如:斜杠前面有空格

示例:

[root@centos001 ~]# find /etc/ -type f -mmin -300 -exec ls -l {} \;    //查找一个小于300分钟内的文件并列出
-rw-r--r--. 1 root root 84 5月 27 22:03 /etc/resolv.conf
  • -size+n/-n: 查找一个文件大于或小于n的文件 需指定文件类型,n后面必须要加单位如:k .m

示例:

[root@centos001 ~]# find /root/ -type f -size +10k -exec ls -l {} \;    //查找一个大于10k的文件并列出
-rw-r--r--. 1 root root 12288 5月  31 14:02 /root/.ssh/.authorized_keys.swp

文件名后缀

  • linux中文件名后缀,不代表一个文件的类型。只是为了方便人们区分
  • 当区分不清中文名时,可以把语言切换至英文加以区分 :

示例:

[root@centos001 ~]# LANG=en  //将系统语言改成英语
[root@centos001 ~]# echo $LANG    //查看系统语言
en
[root@centos001 ~]# stat 2.txt 
  File: '2.txt'
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd00h/64768d	Inode: 33575023    Links: 1
Access: (0664/-rw-rw-r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2018-05-26 10:18:17.839439736 +0800          //先在就比中文更好区分了
Modify: 2018-05-26 09:58:25.036568990 +0800
Change: 2018-05-26 10:17:57.282645569 +0800
 Birth: -

转载于:https://my.oschina.net/u/3707523/blog/1827192

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值