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
命令用法
  1. ctrl +l 光标定位到第一行

  2. ctrl +d 退出一个终端

  3. ctrl +c 取消

  4. crtl +u 删除光标前的命令

  5. crtl +K 删除光标后的命令

  6. crtl +a 光标最开始

  7. 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 回车 (文件传到当前目录)