设为首页 收藏本站
查看: 728|回复: 0

[经验分享] Centos7 find命令与文件后缀

[复制链接]

尚未签到

发表于 2018-4-20 13:53:52 | 显示全部楼层 |阅读模式
find命令
小知识点

  •   which /是查询环境变量范围里面用的
[root@aminglinux-01 ~]# which
lsalias ls='ls --color=auto'
/usr/bin/ls
[root@aminglinux-01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/

  •   whereis /在一个时间段定期更新的一个库里搜索文件,不常用
[root@aminglinux-01 ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz

  •   locate /需要通过yum install -y mlocate 安装这个命令。 安装后不能用,数据库每天凌晨4点自动生成,手动生成updatedb,使用后结果如下,查询的包含123的文件或路径全部列出来。
[root@aminglinux-01 ~]# ls   
111  123  1.txt  234  2.txt  3.txt  aminglinux  anaconda-ks.cfg
[root@aminglinux-01 ~]# locate
123/usr/lib/modules/3.10.0-514.el7.x86_64/kernel/drivers/media/dvb-frontends/cx24123.ko
/usr/lib64/gconv/IBM1123.so

  •   stat 查看文件信息,如stat 1.txt
  •   LANG 更改语言命令,如更改成英语命令LANG=en
  •   echo $LANG 查看语言环境文件
[root@aminglinux-01 ~]# echo "121212" >> 1.txt  //这条命令的意思就是在1.txt里面追加了一行字符串是121212命令用法

  •   ctrl +l 光标定位到第一行
  •   ctrl +d 退出一个终端
  •   ctrl +c 取消
  •   crtl +u 删除光标前的命令
  •   crtl +K 删除光标后的命令
  •   crtl +a 光标最开始
  •   crtl +e 光标最后面
find命令

  •   -name 名字匹配
  •   -type 文件类型
  •   -type d 目录匹配
  •   -type f 文件
[root@aminglinux-01 ~]# find /etc/ -name "sshd_config"   //知道文件名,但不知道探索
/etc/ssh/sshd_config
[root@aminglinux-01 ~]# find /etc/ -name "sshd*"  //不清楚目录名及文件名,直接把带sshd的文件与目录都搜索出来。/etc/ssh/sshd_config/etc/systemd/system/multi-user.target.wants/sshd.service/etc/sysconfig/sshd/etc/pam.d/sshd
[root@aminglinux-01 ~]# find /etc/ -type d -name "sshd*"   //指定搜索带目录的
[root@aminglinux-01 ~]# find /etc/ -type f -name "sshd*"   //指定类型为f的文件与目录
/etc/ssh/sshd_config/etc/sysconfig/sshd/etc/pam.d/sshd

  •   -type l 软链接文件
  •   -type b 块设备文件
  •   -type c 字符串
  •   -mtime 文件改动 时间变化
  •   -ctime 写入文件更改权限 (inode 变化而变化)
  •   -atime 在文件读取或者执行,时间变化
  •   -1 小于一天,用法find /etc/ -type f -mtime -1 (一天以内发生过更改的文件)
  •   +1 大于一天,用法find /etc/ -type f -mtime +1 (一天以前发生过更改的文件)
  •   -0 或者,用法:
[root@aminglinux-01 ~]# find /etc/ -type f -o -mtime -1 -o -name "*.conf"

  •   -inum 用法find / -inum 33580670 通过inode号去找到硬链接文件
  •   -mmin - 60 一小时(60分钟)以内 通过find去查找一个文件时间更改过的记录
[root@aminglinux-01 ~]# find /root/ -type -f -mmin -60

  •   -exec 表示结果输出后 {}, {} 表示列举出来的文件 \ 脱意 ;结尾
[root@aminglinux-01 ~]# find /root/ -type f -mmin -60 -exec ls -l {} \;

  •   实验(给root下在某个时间的文件全部加后缀.bak)
[root@aminglinux-01 ~]# find /root/ -type f -mmin -60/root/1_heard.txt/root/1_sorft.txt/root/1.txt
[root@aminglinux-01 ~]# find /root/ -type f -mmin -60 -exec mv {} {}.bak \;
[root@aminglinux-01 ~]# find /root/ -type f -mmin -60
/root/1_heard.txt.bak
/root/1_sorft.txt.bak
/root/1.txt.bak

  •   -size -10k或-10M
  •   -size +10K或+10M 实验用/tmp/目录
[root@aminglinux-01 ~]# find /tmp/ -size +10k/tmp/ls2
[root@aminglinux-01 ~]# find /tmp/ -type f -size +10k -exec ls -lh {} \;
-rwxr-xr-x. 1 root root 115K 10月 25 20:46 /tmp/ls2
[root@aminglinux-01 ~]# find /tmp/ -type f -size -10k -exec ls -lh {} \;
-rw-------. 1 root root 0 10月 17 05:02 /tmp/yum.log
-rwx------. 1 root root 836 10月 17 05:13 /tmp/ks-script-vVv2O8
-rw-r--r--. 1 root root 0 10月 25 20:01 /tmp/aminglinux/2/2.txt
-rw-r--r--. 2 root root 0 10月 27 20:04 /tmp/1.txt.bak
[root@aminglinux-01 ~]# find /tmp/ -type f -size -10M -exec ls -lh {} \;
-rw-------. 1 root root 0 10月 17 05:02 /tmp/yum.log
-rwx------. 1 root root 836 10月 17 05:13 /tmp/ks-script-vVv2O8
-rw-r--r--. 1 root root 0 10月 25 20:01 /tmp/aminglinux/2/2.txt
-rwxr-xr-x. 1 root root 115K 10月 25 20:46 /tmp/ls2
-rw-r--r--. 2 root root 0 10月 27 20:04 /tmp/1.txt.bak
[root@aminglinux-01 ~]# find /tmp/ -type f -size +10M -exec ls -lh {} \;文件名后缀

  •   .gz 压缩文件
  •   .conf 配置文件
  •   .txt 文本
linux与windows互传文件

  •   xshell securecet 前提要使用这两个软件才可以使用命令上传下载文件
  •   lrzsz 安装yum install -y lrzsz
  •   sz 从linux传到windows 用法sz 1.txt
  •   rz 从windows传到linux 用法rz 回车 (文件传到当前目录)
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-449722-1-1.html 上篇帖子: Centos7 wordpress4.8.2 下篇帖子: centos6上虚拟主机的实现
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表