2.23/2.24/2.25 find命令

which命令

  • which 搜索命令的绝对路径(搜索的目录,默认为 echo $ PATH 该变量下的目录),前提必须得在默认变量下的目录下,同时还得有执行权限,才能搜索得到。

whereis、locate命令

  • whereis命令是搜索文件的
    • whichis命令,通过预先生成的一个文件列表库查找与给出的文件名相关文件。 (有局限性)
  • whereis 【-bms】 【文件名】
    • -b:只查找二进制文件
    • -m:只查找帮助文件(在man目录下的文件)
    • -s:只查找源代码文件
  • locate命令——>安装包 yum install -y mlocate (模糊搜索)
    • 通过预先生成的文件列表库来告诉用户要查找的文件在哪,后面直接跟文件名 locate搜索到的文件列表,不管是目录名还是文件名,只要包含关键词,都会列出来。( locate命令,不会搜索 tmp 下的文件)
      • 使用需要先产生库文件,可以手动升级 updatedb 更新数据库

linux基础快捷键

  • Linux快捷键使用:
    • ctrl+l:清屏
    • ctrl+d: 退出终端;或者输入命令瑞出,exit 或者 logout(在行内有字符的情况下是向后删)
    • ctrl+c:直接取消、暂停当前正在运行的进程、取消当前输入
    • ctrl+u:清除当前光标位置至最前内容
    • ctrl+k:清除当前光标位置至最后内容
    • ctrl+e:移动光标是末尾
    • ctrl+a:移动光标是开头
    • ctrl+z:暂停进程运行 fg 可以会之前暂停的进程
    • ctrl+s:暂停动态运行的进程的屏幕 ctrl+q 恢复屏幕动态

find命令

  • find命令语法:
    • find [路径][参数]
  • find 搜索用 用法:
  1. 根据名字查找
  • find 路径 -name “文件名字 ” 去搜索
[root@hf-01 ~]# find /etc/ -name "sshd_config"
/etc/ssh/sshd_config
[root@hf-01 ~]# 
  • find只知道名字的模糊搜索
[root@hf-01 ~]# find /etc/ -name "sshd*"
/etc/sysconfig/sshd
/etc/ssh/sshd_config
/etc/pam.d/sshd
/etc/systemd/system/multi-user.target.wants/sshd.service
[root@hf-01 ~]# 
  1. 根据文件类型查找
  • find 路径 -type 文件类型
    • d(目录)
    • f(普通的文件)——>二进制的、或文本文档都可以列出来
    • l(软链接文件)
    • s、c(字符串设备文件)
    • b(块设备文件)-name
指定只要目录去搜索
[root@hf-01 ~]# find /etc/ -type d -name "sshd*"

指定类型去搜索
[root@hf-01 ~]# find /etc/ -type f -name "sshd*"
/etc/sysconfig/sshd
/etc/ssh/sshd_config
/etc/pam.d/sshd
[root@hf-01 ~]# 

stat命令

  • stat命令可以列出文件的具体信息,包括atime、ctime、mtime
  • 格式:stat 文件/目录
  • stat 2.txt
    • 三个时间属性:
    • Access time 为最近访问时间
    • Modify time 为最近创建或更改时间 (更改内容会改变时间)
    • Change time 为更改文件,更改权限,更改属组,属主时间(更改文件大小,也会改变)
  1. 根据时间查找
  • 最近访问为atime、 最近更改(更改的是文件的内容,包括创建)为mtime、 最近改动(更改所有者、权限、大小,随着inode更改而更改等)为ctime。
    • ①文件的access time(atime)是在读取文件或执行文件时更改的。
    • ②文件的modified time(mtime)是在写入文件时随文件的内容更改而更改的。
    • ③文件的change time (ctime)是在写入文件,更改所有者、权限或链接设置时随着inode内容更改而更改。 inode(索引节点)用来存放档案及目录的基本信息,包含时间信息、文档名、所有者以及所属组。
  • 更改文件的内容即会更改mtime和ctime,但文件的ctime更改了,mtime未必会会更改,如:更改了文件权限,但是文件内容没有变化。
  • 三个time的属性值都放在了inode中,若mtime,atime被修改,那么inode一定会更改,既然inode更改了,那么ctime也就会跟着更改。
  • -o :或者的意思 or 查找atime更改小于一天的文件
  • 查找,etc目录下, f 类型,一天以内mtime有变动的文件(+1:当天以外,-1:当天)
[root@hf-01 ~]# find /etc/ -type f -mtime -1
/etc/tuned/active_profile
/etc/resolv.conf
[root@hf-01 ~]# 
  • 查找,etc目录下, f 类型,一天以内mtime有变动的,且文件名以conf结尾的文件
[root@hf-01 ~]# find /etc/ -type f -mtime -1 -name "*.conf"
/etc/resolv.conf
[root@hf-01 ~]# 
  • 查找,etc目录下, f 类型,或者一天以内mtime有变动的,或者文件名以conf结尾的文件
[root@hf-01 ~]# find /etc/ -type f -o -mtime -1 -o  -name "*.conf"
  • 查找,etc目录下, f 类型,小于60分钟内改动过,且文件名以conf结尾的文件
[root@hf-01 ~]# find /etc/ -type f -mmin -60 -name "*.conf"
  1. find查找文件的硬链接
  • find 【路径】-inum inode号
[root@hf-01 ~]# ls -l 1_heard.txt 
-rw-r--r-- 2 root root 0 2月  13 22:31 1_heard.txt
[root@hf-01 ~]# ls -i 1_heard.txt 
76239367 1_heard.txt
[root@hf-01 ~]# find / -inum 76239367
/root/1_heard.txt
/tmp/1.txt.bak
[root@hf-01 ~]# 
  • 使用find查找inode号,来找到这个硬链接文件
  1. find查找到文件后,直接显示出结果
  • find 【路径】【参数】 -exec 【命令】 { } (这是空格);
    • 注意:结尾一定要有 ;
[root@hf-01 ~]# find /etc/ -type f -mtime -1 -name "*.conf" -exec ls -l {} \;
-rw-r--r-- 1 root root 54 2月  13 17:04 /etc/resolv.conf
[root@hf-01 ~]# 
  • 查找,根目录下, f 类型,小于60分钟内改动过,把查找到的结果显示出来
find / -type f -mmin -60 -exec ls -l {} \;
  • 查找,根目录下, f 类型,小于60分钟内改动过,把查找的结果更改为以bak结尾的文件
find / -type f -mmin -60 -exec mv {} {}.bak \;
  1. find根据文件大小查找
  • -size 可以查看 k(文件大小为k),M(文件大小为兆)——>小写m会报错
  • 查找root目录下大于10k的文件
[root@hf-01 ~]# find /root/ -size +10k
/root/.bash_history
/root/zabbix-release-3.2-1.el7.noarch.rpm
/root/shell/.fun3.sh.swp
[root@hf-01 ~]# 
  • 查找,root目录下, f 类型,大于10k的文件,把查找到的结果显示出来
[root@hf-01 ~]# find /root/ -type f -size +10k -exec ls -lh {} \;
-rw-------. 1 root root 28K 2月  10 00:20 /root/.bash_history
-rw-r--r--. 1 root root 14K 9月  14 2016 /root/zabbix-release-3.2-1.el7.noarch.rpm
-rw------- 1 root root 12K 2月   8 00:15 /root/shell/.fun3.sh.swp
[root@hf-01 ~]# 

转载于:https://my.oschina.net/u/3707314/blog/1556976

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值