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

find命令

搜索工具:node

  • 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不适合精准查找。linux

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

-name 按文件名搜索ssh

-type 按类型搜索工具

-size 按文件大小搜索spa

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

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

-ctime 按更改文件属性时间搜索(如全部者,权限,连接)it

  • -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系统中,文件的后缀名没有具体的意义,加或者不加都无所谓。

相关文章
相关标签/搜索