简单的linux系统学习笔记——07

一、虚拟机克隆

本体删了,克隆机也会消失

1.先关闭虚拟机

2.右键虚拟机点管理,点击克隆

3.克隆源选择“虚拟机中的当前状态”

4.克隆类型选择“创建链接克隆”

5.编辑虚拟机名字,设置存放路径

6.点击完成

7.修改主机名

8.更改ip,修改网卡

9.重启,保存快照

二、文件

文件属性:

1)权限

2)类型

3)大小

4)时间

5)文件所属

文件相关命令:
file  //查看文件信息
find  //找文件
which //命令(文件)
tar   //压缩与解压缩

三、查看文件的详细信息

属性解释
[root@c7-100 ~]# ll -i 11.txt
67168144 -rw-r--r--. 1 root root 567 7月  18 19:06 11.txt

67168144   //inode号,系统中文件存储在磁盘中的唯一标识,类似座位号
-          //代表是普通文件(d:目录  -:普通文件)
rw-r--r--  //【rw-】:属主的权限【r--】:属组的权限【r--】:其他用户
1          //文件的硬链接数量
root       //属主
root       //属组
567        //字节大小 8bit=1字节  1024字节=1kb  1024kb=1m  1024m=1g 1024g=1t 1024t=1p                                                                              1024p=1e
7月  18 19:06  //时间
11.txt     //文件名称



查看文件更更更详细的信息
[root@c7-100 ~]# stat 11.txt
  文件:"11.txt"
  大小:567       	块:8          IO 块:4096   普通文件
设备:803h/2051d	Inode:67168144    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2024-07-18 19:06:06.639381353 +0800     //最近查看
最近更改:2024-07-18 19:06:00.394988485 +0800     //最近一次内容被修改的时间
最近改动:2024-07-18 21:57:51.998889054 +0800     //属性信息发生变化的时间
创建时间:-

四、文件类型分类

linux的拓展名,只是标识作用,没有实际意义
.config  //配置文件
.rpm     //安装包格式
.tar  .gz  .zip  //压缩包格式
.log     //日志文件


使用【file】命令查看一个文件的类型
[root@c7-100 ~]# file jb.sh
jb.sh: Bourne-Again shell script, UTF-8 Unicode text executable


以符号区分
-  //普通文件
d  //目录
l  //连接文件
****拓展****
c  //字符设备文件(无法查看全是乱码)
b  //block,块设备文件
s  //socket,进程与进程之间本机内通信使用的文件

五、文件相关的命令

1.file命令

查看文件类型

#普通文件
[root@c7-100 ~]# file 1.txt 
1.txt: ASCII text

#图片
[root@c7-100 ~]# file banner.jpg 
banner.jpg: JPEG image data, EXIF standard

#链接文件
[root@c7-100 ~]# file /etc/rc.local
/etc/rc.local: symbolic link to `rc.d/rc.local'

#目录
[root@c7-100 ~]# file /etc
/etc: directory

#块设备
[root@c7-100 ~]# file /dev/sda1
/dev/sda1: block special

#压缩文件
[root@c7-100 ~]# file html.zip 
html.zip: Zip archive data, at least v1.0 to extract

2.which查看命令文件路径

[root@c7-100 ~]# which vim
/usr/bin/vim

3.find查找文件位置

【【【  find + 要查找的位置路径 + 参数 + 搜索的值(内容)  】】】

通过文件名查找【-name】
[root@c7-100 ~]# find / -name "ifcfg-eth0"
/etc/sysconfig/network-scripts/ifcfg-eth0

忽略大小写查找【-iname】
[root@c7-100 ~]# find ./ -name a.txt
./a.txt
[root@c7-100 ~]# find ./ -iname a.txt
./A.txt
./a.txt

[root@c7-100 ~]# cat `find / -name "ifcfg-eth0"`  //【``】先执行反引号中的内容
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
NAME=eth0
UUID=6083d416-be6b-4efb-9459-1021d85c8a6f
DEVICE=eth0
ONBOOT=yes
IPADDR=10.0.0.100
PREFIX=24
GATEWAY=10.0.0.2
DNS1=223.5.5.5


通过文件时间查找【-mtime】以天为单位
[root@c7-100 ~]# find / -mtime +2  //两天之前所创建的文件
[root@c7-100 ~]# find / -mtime -2  //两天之内创建的文件

通过文件时间查找【-mmin】以分钟为单位
[root@c7-100 ~]# find / -mmin +2   //两分钟之前创建
[root@c7-100 ~]# find / -mmin -2   //两分钟之内创建


通过文件类型查找【-type】
-  //find:f
d  //d
l  //l

[root@c7-100 ~]# find /etc/ -type l
[root@c7-100 ~]# find /etc/ -type d
[root@c7-100 ~]# find /etc/ -type f

组合使用
[root@c7-100 ~]# find / -type f -name *-eth0
/etc/sysconfig/network-scripts/ifcfg-eth0

取反
[root@c7-100 ~]# find / ! -type f -name *-eth0


通过文件大小查找【-size】
查找家目录下,大于5m文件
[root@c7-100 ~]# find ~ -size +5M
/root/2.txt
/root/3.txt
/root/1.txt


查找家目录下,小于15m的文件
[root@c7-100 ~]# find ~ -size -15M


总结
[root@c7-100 ~]# find ~ -size -15M   //小于15m
                              -15    //小于15字节  默认【15c】
                              -15G   //小于15G
                              -15k   //小于15kb
                              
                              
*** 拓展 ***
通过权限查找【-perm】
[root@c7-100 ~]# find ~ -perm 755
/root/a
/root/b
/root/b/qwe
/root/c
/root/hi

4.tar压缩与解压

压缩作用:

1.节省空间

2.增加传输效率

原理:

1.创建一个空的压缩文件

2.将被压缩为放进去文件

【【【  tar + zcvf + 压缩文件名称 + 要压缩的文件  】】】
[root@c7-100 test]# ll
总用量 4
-rw-r--r--. 1 root root   0 7月  18 15:23 1.txt
-rw-r--r--. 1 root root 312 7月  18 21:59 33.txt
drwxr-xr-x. 2 root root   6 7月  18 15:11 a
drwxr-xr-x. 3 root root  28 7月  18 15:21 b
[root@c7-100 test]# tar zcvf yasuo.tar.gz ./*
./1.txt
./33.txt
./a/
./b/
./b/qwe/
./b/ihi
[root@c7-100 test]# ll
总用量 8
-rw-r--r--. 1 root root   0 7月  18 15:23 1.txt
-rw-r--r--. 1 root root 312 7月  18 21:59 33.txt
drwxr-xr-x. 2 root root   6 7月  18 15:11 a
drwxr-xr-x. 3 root root  28 7月  18 15:21 b
-rw-r--r--  1 root root 378 7月  25 11:21 yasuo.tar.gz

参数解释
z  //压缩数据的方式:zzip
c  //创建压缩包
v  //显示压缩过程
f  //识别压缩包生成的路径
h  //跟随软连接,将源文件进行压缩

解压前查看文件内容

【tf】解压文件前查看,不能查看压缩包里文件夹的内容
[root@c7-100 test]# tar tf yasuo.tar.gz
./1.txt
./33.txt
./a/
./b/
./b/qwe/
./b/ihi

解压压缩包

【xvf】(x解压)
[root@c7-100 test]# tar xvf yasuo.tar.gz -C /t1

-C  //指定路径

5.命令结合使用

find与tar

创建测试数据
[root@c7-100 old]# touch old{1..3}
[root@c7-100 old]# touch old{1..3}.txt
[root@c7-100 old]# ll /old
总用量 0
-rw-r--r-- 1 root root 0 7月  25 15:07 old1
-rw-r--r-- 1 root root 0 7月  25 15:07 old1.txt
-rw-r--r-- 1 root root 0 7月  25 15:07 old2
-rw-r--r-- 1 root root 0 7月  25 15:07 old2.txt
-rw-r--r-- 1 root root 0 7月  25 15:07 old3
-rw-r--r-- 1 root root 0 7月  25 15:07 old3.txt

找到以.txt结尾的文件,并压缩以【``】方式
[root@c7-100 old]# tar zcvf ha.tar.gz `find /old -name "*.txt"`
tar: 从成员名中删除开头的“/”
/old/old1.txt
/old/old2.txt
/old/old3.txt
[root@c7-100 old]# ll /old
总用量 4
-rw-r--r-- 1 root root 139 7月  25 15:13 ha.tar.gz
-rw-r--r-- 1 root root   0 7月  25 15:07 old1
-rw-r--r-- 1 root root   0 7月  25 15:07 old1.txt
-rw-r--r-- 1 root root   0 7月  25 15:07 old2
-rw-r--r-- 1 root root   0 7月  25 15:07 old2.txt
-rw-r--r-- 1 root root   0 7月  25 15:07 old3
-rw-r--r-- 1 root root   0 7月  25 15:07 old3.txt
[root@c7-100 old]# tar tf ha.tar.gz 
old/old1.txt
old/old2.txt
old/old3.txt


以【|】的方式
[root@c7-100 old]# find ./ -name "*.txt" |xargs tar zcvf wa.tar.gz  //xargs是分组
./old1.txt
./old2.txt
./old3.txt
[root@c7-100 old]# tar tf wa.tar.gz 
./old1.txt
./old2.txt
./old3.txt


- 【了解即可】【exec】方式结合使用(逐条执行)
[root@c7-100 old]# find ./ -name "*.txt" -exec tar zcvf  wahh.tar.gz {} \; 
./old1.txt
./old2.txt
./old3.txt
[root@c7-100 old]# tar tf wahh.tar.gz 
./old3.txt

六、xargs分组显示

[root@c7-100 old]# find ./ -name "*.txt" | xargs
./old1.txt ./old2.txt ./old3.txt

[root@c7-100 old]# find ./ -name "*.txt" | xargs -n2
./old1.txt ./old2.txt
./old3.txt

[root@c7-100 old]# find ./ -name "*.txt" | xargs -n3
./old1.txt ./old2.txt ./old3.txt

[root@c7-100 old]# find ./ -name "*.txt" | xargs -n1
./old1.txt
./old2.txt
./old3.txt

07-完

  • 14
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值