Chinaunix首页 | 论坛 | 博客
  • 博客访问: 141620
  • 博文数量: 70
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 770
  • 用 户 组: 普通用户
  • 注册时间: 2017-11-04 11:19
文章分类

全部博文(70)

文章存档

2018年(69)

2016年(1)

我的朋友

分类: LINUX

2018-06-06 23:53:17

2.23 命令find(上)
1)which查找命令文件:在环境变量中查找相关命令的文件所在位置。
2)[root@localhost ~]# whereis ls
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz
关于whereis:
NAME
       whereis  -  locate the binary, source, and manual page files for a com‐
       mand
3)locate:使用需要先安装,安装之后还需要配置
[root@localhost ~]# yum -y install mlocate            //安装方式
[root@localhost ~]# locate ls
locate: 无法执行 stat () `/var/lib/mlocate/mlocate.db': 没有那个文件或目录    //需要产生".db"文件。文件列表的一个数据库。
[root@localhost ~]# updatedb        //生成文件列表数据库文件,这是手动生成。默认会在每天凌晨四点自动生成一次。
[root@localhost ~]# locate 123        //查找到了相关文件。
/usr/lib/modules/3.10.0-693.el7.x86_64/kernel/drivers/media/dvb-frontends/cx24123.ko.xz
/usr/lib64/gconv/IBM1123.so

4)find:查找文件
组合键
“ctrl+l”:清屏
“ctrl+d”:退出一个终端。=exit或logout
“ctrl+c”:取消当前命令的执行。
“ctrl+u”:清空光标前的所有内容
“ctrl+k”:清空光标后的所有内容
“ctrl+e”:移动光标到行尾。

“ctrl+a”:移动光标到行首


[root@localhost ~]# find /etc/ -name "sshd_config"
/etc/ssh/sshd_config
[root@localhost ~]# find /etc/ -name "sshd*"                //模糊查找,使用“*”通配符。文件目录都会被查找出来。
/etc/ssh/sshd_config
/etc/systemd/system/multi-user.target.wants/sshd.service
/etc/sysconfig/sshd
/etc/pam.d/sshd

指定查找文件类型:之前讲过的文件类型都可以在这里进行搜索(d,f,l,s,c,b)
[root@localhost ~]# find /etc/ -type d -name "sshd*"            //查找目录
[root@localhost ~]# find /etc/ -type f -name "sshd*"            //查找目文件

[root@localhost ~]# find /etc/ -type l
/etc/ssl/certs
/etc/grub2.cfg
[root@localhost ~]# ls -l /etc/ssl/certs            //确实是软链接文件。
lrwxrwxrwx. 1 root root 16 5月  30 07:01 /etc/ssl/certs -> ../pki/tls/certs

[root@localhost ~]# find /dev/ -type b            //块文件
/dev/sda1
[root@localhost ~]# ls -l /dev/sda1
brw-rw----. 1 root disk 8, 1 6月   1 21:13 /dev/sda1
//还比如/dev目录下还有“c”文件。

find  查找范围  -查找条件


2.24  命令find(中)
[root@localhost ~]# stat 1    //查看文件的具体信息
  文件:"1"
  大小:19        块:0          IO 块:4096   目录
设备:803h/2051d Inode:491         硬链接:2
权限:(0755/drwxr-xr-x)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2018-06-06 00:26:19.860876661 +0800
最近更改:2018-06-06 00:26:09.649927606 +0800
最近改动:2018-06-06 00:26:09.649927606 +0800        //主要看这里的三项
创建时间:-

find可能使用到的时间参数。这个部分对于文件或目录的测试执行方式类似的。所以我就选择使用目录来进行验证了。
-ctime:指最近改动时间,修改的内容是指inode中记录的内容,比如权限,文件名,时间
-mtime:指最近更改时间,修改了文件的具体内容,文件中的内容。(并且ctime会一起变动)
-atime:指最近访问时间,对于目录,进入就算访问;对于文件,cat或vim查看,就算访问。

[root@localhost ~]# chmod 700 1
[root@localhost ~]# stat 1
  文件:"1"
  大小:19        块:0          IO 块:4096   目录
设备:803h/2051d Inode:491         硬链接:2
权限:(0700/drwx------)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2018-06-06 00:26:19.860876661 +0800
最近更改:2018-06-06 00:26:09.649927606 +0800
最近改动:2018-06-06 23:02:14.129878095 +0800
创建时间:-

为了查看明显:
[root@localhost ~]# LANG=en
[root@localhost ~]# stat 1
  File: '1'
  Size: 19        Blocks: 0          IO Block: 4096   directory
Device: 803h/2051d Inode: 491         Links: 2
Access: (0700/drwx------)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2018-06-06 00:26:19.860876661 +0800
Modify: 2018-06-06 00:26:09.649927606 +0800
Change: 2018-06-06 23:02:14.129878095 +0800
 Birth: -

atime:例子
[root@localhost ~]# cd 1            //访问了目录
[root@localhost 1]# ls
a.txt  abc
[root@localhost 1]# cd -
/root
[root@localhost ~]# stat 1
  File: '1'
  Size: 30        Blocks: 0          IO Block: 4096   directory
Device: 803h/2051d Inode: 491         Links: 3
Access: (0700/drwx------)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2018-06-06 23:08:27.260335823 +0800                //atime发生变化
Modify: 2018-06-06 23:06:33.969586453 +0800
Change: 2018-06-06 23:06:33.969586453 +0800
 Birth: -

举例:
[root@localhost ~]# find / -type f -mtime -1        //最近更改时间在一天以内的
[root@localhost ~]# find / -type f -mtime +1        //最近更改时间在一天以上

[root@localhost ~]# find / -type f -ctim-1        //最近改动时间在一天以内的
[root@localhost ~]# find / -type f -ctime +1        //最近改动时间在一天以上

[root@localhost ~]# find / -type f -atime -1        //最近访问时间在一天以内的
[root@localhost ~]# find / -type f -atime +1        //最近访问时间在一天以上

[root@localhost ~]# find /etc -type f -mtime -1 -name "*.conf"    //几个条件是“并且”关系。
/etc/resolv.conf

[root@localhost ~]# find /etc -type f -o -mtime -1 -o -name "*.conf"
//几个条件去“或者”关系。不过一般不会这么用。


2.25 命令find(下)
[root@localhost ~]# ln 1_heard.txt /tmp/1.txt.bak        //创建硬链接
[root@localhost ~]# ls -l 1_heard.txt 
-rw-r--r--. 2 root root 0 Jun  6 23:22 1_heard.txt        //这里硬链接数为2
[root@localhost ~]# ls -i 1_heard.txt         //查看该文件inode号
33576920 1_heard.txt

如果想要找到硬链接文件,那么只能通过inode号相同这一点查找。
[root@localhost ~]# find / -inum 33576920        //这里是指“-inode number”。找文件硬链接
/root/1_heard.txt
/tmp/1.txt.bak

[root@localhost ~]# find /root/ -type f -mmin -60        //一小时以内更改过的文件
/root/1_heard.txt
[root@localhost ~]# ls -l /root/1_heard.txt
-rw-r--r--. 2 root root 0 Jun  6 23:22 /root/1_heard.txt
[root@localhost ~]# date
Wed Jun  6 23:28:04 CST 2018

[root@localhost ~]# find /root/ -type f -mmin -60 -exec ls -l {} \;    //格式,”{}“表示前面命令列出的文件。也可以说是标准格式。
-rw-r--r--. 2 root root 0 Jun  6 23:22 /root/1_heard.txt
“-exec”是find的一个选项

[root@localhost ~]# find /root/ -type f -mtime -1 -exec cp {} {}.bak \;    //拷贝
[root@localhost ~]# ls /root/
1  1_heard.txt  1_heard.txt.bak  2  anaconda-ks.cfg

[root@localhost ~]# find /root/ -type f -size +10k -exec ls -lh {} \;        //查找文件大小大于10K的文件
-rw-r--r--. 2 root root 12K Jun  6 23:36 /root/1_heard.txt

2.26 文件后缀名
Linux下也是有后缀名的。但是并不像win一样,使用文件名后缀严格的指定文件格式。并不能代表文件类型。但是会习惯性的定义,比如文本文件定义为”.txt“,主配置文件”.conf“或”.cnf“等

[root@localhost ~]# date                //查看系统时间
Wed Jun  6 23:42:37 CST 2018
[root@localhost ~]# echo $LANG    //当前环境使用语言,英文。
en
[root@localhost ~]# echo $LANG        //中文,需要在安装过程中,安装支持中文才可以。
zh_CN.UTF-8

2.27 Linux和win互传文件
之后会学习ftp、samba服务,实现在系统间传递。不过还可以使用xhsell工具
[root@localhost ~]# yum -y install lrzsz            //首先安装程序
然后操作:将Linux中的文件传到win上。


或者将win中的内容,传到Linux中:

对于主机正在使用的文件(打开中的文件),是无法实现传输的。

或者使用securecrt也是可以的。不过putty就不行了。
总结:
使用xshell程序,并且虚拟机安装”lrzsz“程序。
linux中的文件传输到win主机上:sz file
win主机上的文件传输到Linux中:rz                //传到执行“rz”时所处的当前目录。

阅读(955) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~