(补)2.2学习笔记——find命令、文件名后缀

find命令

搜索工具:

  • which(可查找可执行文件的绝对路径),但需要注意的是which只能用来查找PATH环境变量中出现的路径
[root@linux-128 ~]# which ls
alias ls='ls --color=auto'
	/usr/bin/ls

 

  • locate:和whereis类似,也是通过查找预先生成的文件列表库来查找文件在哪里,后面直接跟文件名;需要安装mlocate软件包:
  • [root@linux-128 ~]# yum install -y mlocate
    [root@linux-128 ~]# updatedb
    [root@linux-128 ~]# locate yum.log
    /var/log/yum.log
    
    

            安装好后,第一次运行locate会报错,需要运行updatedb命令立即生成或者更新这个库文件;默认           情况下这个库每周更新一次;locate不适合精准查找。

  • find命令用法:find 路径 -选项 

-name 按文件名搜索

-type 按类型搜索

-size 按文件大小搜索

-atime 按访问时间,或执行时间搜索

-mtime 按更改文件内容时间搜索

-ctime 按更改文件属性时间搜索(如所有者,权限,链接)

  • -1 小于1天;1天以内
  • +1 大于1天;1天以前
  • 不能等于1
  • -o或者 连接多个条件

例:find  /tmp -name 1.txt  在tmp下按文件名搜索1.txt文件(只会精确搜索)

find  /etc –name “sshd*”模糊搜索

find /etc/ -type d –name “sshd_config”指定类型 d目录 f文件 b块 l软连接

find /etc/ -type f -citme -1 -name "*.conf" 搜索1天内更改文件属性的文件

find / -inum  (inode号) 可以搜索该inode号文件

-mmin 分钟

[root@glinux-01 lianxi1]# find /tmp -type f -mmin -50 //查找tmp下50分钟之内被改动的文件
/tmp/gao/lianxi1/2.txt
/tmp/gao/lianxi1/3.txt

-exec 将find命令搜索出来的结果执行命令 

//-exec后跟linux命令 其中{}会遍历每一个搜索出来的内容。 结尾用\;  与{}有空格

[root@glinux-01 lianxi1]# find /tmp -type f -mmin -50 -exec ls -l {} \;
//-exec后跟linux命令 其中{}会遍历每一个搜索出来的内容。 结尾用\;  与{}有空格
-rw-r--r--. 1 root root 0 2月   5 09:52 /tmp/gao/lianxi1/2.txt
-rw-r--r--. 1 root root 0 2月   5 09:52 /tmp/gao/lianxi1/3.txt

 将搜索出的文件改名.bak

[root@glinux-01 lianxi1]# find /tmp -type f -mmin -50 -exec mv {} {}.bak \;
[root@glinux-01 lianxi1]# find /tmp -type f -mmin -50 -exec ls -l {} \;
-rw-r--r--. 1 root root 0 2月   5 09:52 /tmp/gao/lianxi1/2.txt.bak
-rw-r--r--. 1 root root 0 2月   5 09:52 /tmp/gao/lianxi1/3.txt.bak

find /root/ -type f –size -10k

查找文件大小 小于10k的文件+10k表示大于10k,也可用M兆

不加单位代表使用数据块。1数据块表示512字节=0.5k

stat 文件名  (查看文件详细信息)

[root@glinux-01 lianxi1]# stat 1.txt
  文件:"1.txt"
  大小:0         	块:0          IO 块:4096   普通空文件
设备:803h/2051d	Inode:50679781    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:user_tmp_t:s0
最近访问:2018-01-26 21:42:43.464971964 +0800
最近更改:2018-01-26 21:42:43.464971964 +0800
最近改动:2018-01-26 21:42:43.464971964 +0800

 

文件名后缀

linux文件后缀名 在linux系统中,文件的后缀名没有具体的意义,加或者不加都无所谓。

转载于:https://my.oschina.net/u/3771583/blog/1618316

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值