主要内容:
- 复习回顾:
- date命令
- 文件属性的深入学习
一、回顾练习:
压缩 /etc/及排除//etc/services/外的二者的区别:
1.分别创建两个压缩包
[root@oldedu59 ~]# tar zcf /tmp/etc.tar.gz /etc/
tar: Removing leading `/' from member names
[root@oldedu59 ~]# tar zcf /tmp/etc-paichu.tar.gz /etc/ --exclude /etc/services
tar: Removing leading `/' from member names
[root@oldedu59 ~]# tar tf /tmp/etc.tar.gz |grep services
etc/services
etc/firewalld/services/
[root@oldedu59 ~]# tar tf /tmp/etc-paichu.tar.gz |grep services
etc/firewalld/services/
2.Linux下面的对比工具(比较两个文件的内容)
diff==different
[root@oldedu59 tmp]# tar tf /tmp/etc.tar.gz >/oldboy/tar.txt
[root@oldedu59 tmp]# tar tf /tmp/etc-paichu.tar.gz >/oldboy/tar-paichu.txt
[root@oldedu59 tmp]# diff /oldboy/tar.txt /oldboy/tar-paichu.txt
1950d1949
< etc/services
vimdiff:
[root@oldedu59 tmp]# vimdiff /oldboy/tar.txt /oldboy/tar-paichu.txt
2 files to edit
+ 1 +--1943 lines: etc/--------------|+ +--1943 lines: etc/------------------
1944 etc/udev/udev.conf | etc/udev/udev.conf
1945 etc/udev/hwdb.bin | etc/udev/hwdb.bin
1946 etc/dhcp/ | etc/dhcp/
1947 etc/dhcp/dhclient-exit-hooks.d/ | etc/dhcp/dhclient-exit-hooks.d/
1948 etc/dhcp/dhclient-exit-hooks.d/az| etc/dhcp/dhclient-exit-hooks.d/azure-
1949 etc/dhcp/dhclient.d/ | etc/dhcp/dhclient.d/
1950 etc/services | -------------------------------------
1951 etc/machine-id | etc/machine-id
1952 etc/shadow | etc/shadow
1953 etc/localtime | etc/localtime
1954 etc/subgid | etc/subgid
1955 etc/NetworkManager/ | etc/NetworkManager/
1956 etc/NetworkManager/dispatcher.d/ | etc/NetworkManager/dispatcher.d/
+ 1957 +--497 lines: etc/NetworkManager/|+ +--497 lines: etc/NetworkManager/disp
~ | ~
~ | ~
~ | ~
~ | ~
~ | ~
/oldboy/tar.txt 757,1 All
二、扩展内容:
lrzsz 把文件上传或下载到Linux
rz 把windows文件上传到Linux
sz 把Linux文件下载到windows
三、date命令:显示或设置时间
1.显示时间
- 年月日:+%F===%Y-%m-%d
year mouth day
[root@oldedu59 tmp]# date -d '+10Year' +%F
2029-04-10
[root@oldedu59 tmp]# date +%Y-%m-%d
2019-04-10
- 时分秒:+%T===%H:%M:%S
hour min sec
[root@oldedu59 tmp]# date +%T
09:57:59
[root@oldedu59 tmp]# date +'%F %T'
2019-04-10 09:58:21
- 星期几:+%w ===week 周几
[root@oldedu59 tmp]# date +%w
3
2.常在备份的时候加date命令
3.设置时间:date -s
-s ===set
[root@oldedu59 tmp]# date -s '20190501 19:0:0'
Wed May 1 19:00:00 CST 2019
4.自动同步时间
- ntpdate 根据网站时间同步到系统的时间
网站是阿里云网站:ntp1.aliyun.com
[root@oldedu59 tmp]# date -s '20000101 00:00:00'
Sat Jan 1 00:00:00 CST 2000
[root@oldedu59 tmp]# date
Sat Jan 1 00:00:02 CST 2000
[root@oldedu59 tmp]# date +'%F %T'
2000-01-01 00:00:08
[root@oldedu59 tmp]# ntpdate ntp1.aliyun.com
10 Apr 10:33:01 ntpdate[13625]: step time server 120.25.115.20 offset 608207551.275568 sec
[root@oldedu59 tmp]# date +'%F %T'
2019-04-10 10:33:07
三、文件属性的深入:
1.ls -lhi
-l 显示详细信息
-h 以人类可读的方式显示大小
-i 显示文件或目录的iNode号
[root@oldedu59 ~]# ls -lhi /root
total 24K
33575769 -rw-r--r-- 1 root root 43 Apr 8 15:18 1.txt
33574978 -rw-------. 1 root root 1.5K Mar 26 11:47 anaconda-ks.cfg
16777767 drwxr-xr-x 79 root root 8.0K Apr 10 08:11 etc
33575760 -rw-r--r-- 1 root root 0 Apr 1 09:42 file2.txt
33575019 -rw-r--r-- 1 root root 8 Apr 4 16:14 lod.txt
33575018 -rw-r--r-- 1 root root 0 Apr 1 20:18 meinv.txt
33575761 -rw-r--r-- 1 root root 0 Apr 1 10:27 old
2.echo -n 不显示每行结尾回车
[root@oldedu59 ~]# echo -n oldboy
oldboy[root@oldedu59 ~]#
3.iNode和block
(1)含义:
- iNode : index node 索引节点
iNode号码(身份证号码)
iNode空间 存放文件属性信息(大小、所有者 、权限、文件类型、硬连接数、8修改时间)
block的位置 - block:数据块
block 用来存放文件的内容(实体)
(2)两者之间的关系:显示文件的内容 cat oldboy.txt 与iNode和block的关系?
inode和block关系
https://www.processon.com/diagraming/5cada085e4b0375afbef1ac1
(3)根据iNode号找文件:find -inum
[root@oldboyedu59 ~]# ls -lhi lidao.txt
134342444 -rw-r--r-- 1 root root 6 Apr 10 11:05 lidao.txt
[root@oldboyedu59 ~]# find -inum 134342444
./lidao.txt
(5) 两者的特点
- inode:
inode在文件系统中是唯一的。
一个文件至少占用一个inode及一个block,多个文件可以占用同一个inode(硬链接) - block:
一个block只能被一个文件使用,如果文件很小但是block很大,会造成空间浪费,无法继续呗其他文件使用;如果文件很大,则会占用多个block空间
(6)查看整体情况
block一共多少,用了多少,还有多少(相当于查看磁盘使用情况)
命令:df
-h 人类可读
[root@oldedu59 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 19706880 1748096 17958784 9% /
devtmpfs 1003184 0 1003184 0% /dev
tmpfs 1014044 0 1014044 0% /dev/shm
tmpfs 1014044 9796 1004248 1% /run
tmpfs 1014044 0 1014044 0% /sys/fs/cgroup
/dev/sda1 201380 107004 94376 54% /boot
tmpfs 202812 0 202812 0% /run/user/0
[root@oldedu59 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 19G 1.7G 18G 9% /
devtmpfs 980M 0 980M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 199M 0 199M 0% /run/user/0
查看inode:df -i
[root@oldedu59 ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 9858560 61931 9796629 1% /
devtmpfs 250796 373 250423 1% /dev
tmpfs 253511 1 253510 1% /dev/shm
tmpfs 253511 709 252802 1% /run
tmpfs 253511 16 253495 1% /sys/fs/cgroup
/dev/sda1 102400 326 102074 1% /boot
tmpfs 253511 1 253510 1% /run/user/0
[root@oldedu59 ~]# df -ih
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda3 9.5M 61K 9.4M 1% /
devtmpfs 245K 373 245K 1% /dev
tmpfs 248K 1 248K 1% /dev/shm
tmpfs 248K 709 247K 1% /run
tmpfs 248K 16 248K 1% /sys/fs/cgroup
/dev/sda1 100K 326 100K 1% /boot
tmpfs 248K 1 248K 1% /run/user/0
(7)文件名放在目录的block里面
四、软硬链接
1.硬链接
(1)创建硬链接
[root@oldedu59 oldboy]# touch oldboy >alex.txt
[root@oldedu59 oldboy]# ls
alex oldboy oldboy.txt.hard sf.txt tar.txt
alex.txt oldboy.txt oldboy.txt.soft tar-paichu.txt
[root@oldedu59 oldboy]# ln alex.txt alex.txt.hard
[root@oldedu59 oldboy]# ls -lhi alex.txt*
17083570 -rw-r--r-- 2 root root 0 Apr 10 11:59 alex.txt
17083570 -rw-r--r-- 2 root root 0 Apr 10 11:59 alex.txt.hard
2.软链接
(1)创建软链接
[root@oldedu59 oldboy]# ln -s oldboy.txt oldboy.txt.soft
[root@oldedu59 oldboy]# ls -lhi oldboy.txt*
17083567 -rw-r--r-- 2 root root 75 Apr 9 15:46 oldboy.txt
17083567 -rw-r--r-- 2 root root 75 Apr 9 15:46 oldboy.txt.hard
17083573 lrwxrwxrwx 1 root root 10 Apr 10 12:14 oldboy.txt.soft -> oldboy.txt
3.软链接和硬链接的区别
https://www.processon.com/diagraming/5cada9aae4b0375afbef38e6