Linux基础(二)
文件状态
# 查看文件状态
stat file01
# 文件:"file01"
# 大小:10 块:8 IO 块:4096 普通文件
#设备:fd00h/64768d Inode:33575019 硬链接:1
#权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
#最近访问:2022-08-13 13:40:02.766213381 +0800
#最近更改:2022-08-13 13:40:02.766213381 +0800
#最近改动:2022-08-13 13:40:02.767213381 +0800
#创建时间:-
# 使用touch可以同时更新文件的三个时间
# 最近访问(access time):查看文件时会更新时间
# 最近更改(modify time):修改文件内容时会更新时间
# 最近改动(change time):文件元数据变更时会更新时间
磁盘挂载
# 磁盘挂载,将disk1挂载到路径./download
mount disk1 ./download
软链接、硬链接
# 软链接会创建一个新的文件,文件内容执向链接的文件名,通过文件名进行链接
# 硬链接,指向原有文件内容,与链接文件共用Inode,硬链接数+1
# 软链接
ln -s file01 softLink
stat file01
# 文件:"file01"
# 大小:10 块:8 IO 块:4096 普通文件
#设备:fd00h/64768d Inode:33575019 硬链接:1
#权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
#最近访问:2022-08-13 13:40:02.766213381 +0800
#最近更改:2022-08-13 13:40:02.766213381 +0800
#最近改动:2022-08-13 13:40:02.767213381 +0800
#创建时间:-
stat softLink
# 文件:"softLink" -> "file01"
# 大小:6 块:0 IO 块:4096 符号链接
#设备:fd00h/64768d Inode:33575017 硬链接:1
#权限:(0777/lrwxrwxrwx) Uid:( 0/ root) Gid:( 0/ root)
#最近访问:2022-08-13 13:26:20.209159831 +0800
#最近更改:2022-08-13 13:26:18.977159751 +0800
#最近改动:2022-08-13 13:26:18.977159751 +0800
#创建时间:-
# 硬链接
ln file02 hardLink
stat file02
# 文件:"file02"
# 大小:9 块:8 IO 块:4096 普通文件
#设备:fd00h/64768d Inode:33575016 硬链接:2
#权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
#最近访问:2022-08-13 13:27:12.020163204 +0800
#最近更改:2022-08-13 13:26:59.158162367 +0800
#最近改动:2022-08-13 13:26:59.158162367 +0800
#创建时间:-
stat hardLink
# 文件:"hardLink"
# 大小:9 块:8 IO 块:4096 普通文件
#设备:fd00h/64768d Inode:33575016 硬链接:2
#权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
#最近访问:2022-08-13 13:27:12.020163204 +0800
#最近更改:2022-08-13 13:26:59.158162367 +0800
#最近改动:2022-08-13 13:26:59.158162367 +0800
#创建时间:-
文件传输
windows与linux
# 安装文件传输工具
yum install lrzsz -y
#rz 将文件从windows上传到linux
rz
#sz 将文件从Linux下载到windows
sz file01
linux间
# scp 源数据地址 目标数据地址
# 源数据地址、目标数据地址都支持远程路径
# -r 拷贝文件夹
#从本地拷贝到远程服务器
scp file01 root@192.168.226.102:~
#The authenticity of host '192.168.226.102 (192.168.226.102)' can't be established.
#ECDSA key fingerprint is SHA256:LnDY/uP4vLhPN1Ufr0KpFWKCy2XBxVtLR7nKU6Kw+z8.
#ECDSA key fingerprint is MD5:f3:02:37:7f:e0:76:92:ac:67:4f:88:9d:e8:2f:40:d2.
#Are you sure you want to continue connecting (yes/no)? yes
#Warning: Permanently added '192.168.226.102' (ECDSA) to the list of known hosts.
#root@192.168.226.102's password:
#file01 100% 7 8.0KB/s 00:00
# 从远程服务器拷贝到本地
scp root@192.168.226.102:~/file02 ./
#root@192.168.226.102's password:
#file02 100% 9 7.9KB/s 00:00
# 拷贝文件夹
mkdir -p a/b/c
scp a root@192.168.226.102:~
#root@192.168.226.102's password:
#a: not a regular file
scp -r a root@192.168.226.102:~
#root@192.168.226.102's password:
文件大小查看
#查看分区信息
df -h
#文件系统 容量 已用 可用 已用% 挂载点
#devtmpfs 898M 0 898M 0% /dev
#tmpfs 910M 0 910M 0% /dev/shm
#tmpfs 910M 8.5M 902M 1% /run
#tmpfs 910M 0 910M 0% /sys/fs/cgroup
#/dev/mapper/centos-root 18G 1.4G 17G 8% /
#/dev/sda1 253M 131M 122M 52% /boot
#tmpfs 182M 0 182M 0% /run/user/0
#查看当前目录文件大小
du -h
#4.0K ./.ssh
#0 ./a/b/c
#0 ./a/b
#0 ./a
#40K .
#最大深度2
du -h --max-depth=2
#4.0K ./.ssh
#0 ./a/b
#0 ./a
#40K .
#查看根目录最大深度为1
du -h --max-depth=1 /
#118M /boot
#0 /dev
#du: 无法访问"/proc/54726/task/54726/fd/4": 没有那个文件或目录
#du: 无法访问"/proc/54726/task/54726/fdinfo/4": 没有那个文件或目录
#du: 无法访问"/proc/54726/fd/3": 没有那个文件或目录
#du: 无法访问"/proc/54726/fdinfo/3": 没有那个文件或目录
#0 /proc
#8.5M /run
#0 /sys
#24M /etc
#40K /root
#239M /var
#8.0K /tmp
#1.1G /usr
#0 /home
#0 /media
#0 /mnt
#0 /opt
#0 /srv
#1.5G /
文件的压缩与解压
tar
# 压缩 tar -zc(压缩)f(文件) 压缩文件地址 源文件地址
tar -zcf a.tar.gz a
rm -r a
#rm:是否进入目录"a"? y
#rm:是否进入目录"a/b"? y
#rm:是否删除目录 "a/b/c"?y
#rm:是否删除目录 "a/b"?y
#rm:是否删除目录 "a"?y
ll
#总用量 16
#-rw-------. 1 root root 1534 8月 3 08:54 anaconda-ks.cfg
#-rw-r--r-- 1 root root 131 8月 13 15:01 a.tar.gz
#-rw-r--r-- 1 root root 7 8月 13 14:33 file01
#-rw-r--r-- 1 root root 9 8月 13 14:39 file02
# 压缩 tar -zx(解压)v(打印过程)f(文件) 文件
tar -zxvf a.tar.gz
#a/
#a/b/
#a/b/c/
ls
#a anaconda-ks.cfg a.tar.gz file01 file02
mkdir b
# 解压文件到指定目录下
tar -zxvf a.tar.gz -C b
#a/
#a/b/
#a/b/c/
ls b
#a
zip
# 安装压缩工具
yum install zip unzip -y
mkdir -p zipfile/a/b
#压缩
#zip -r 压缩后文件名 待压缩文件名
zip -r zipfile.zip zipfile
# adding: zipfile/ (stored 0%)
# adding: zipfile/a/ (stored 0%)
# adding: zipfile/a/b/ (stored 0%)
rm -rf zipfile
ls
#a anaconda-ks.cfg a.tar.gz file01 file02 zipfile.zip
#解压缩
#unzip 文件名
unzip zipfile.zip
#Archive: zipfile.zip
# creating: zipfile/
# creating: zipfile/a/
# creating: zipfile/a/b/
ls
#a anaconda-ks.cfg a.tar.gz file01 file02 zipfile zipfile.zip
DNS域名解析
vi /etc/hosts
#添加如下信息
#192.168.226.101 hadoop101
#192.168.226.102 hadoop102
#192.168.226.103 hadoop103
#通过scp分发到其他服务器
scp /etc/hosts root@hadoop103:/etc/
#The authenticity of host 'hadoop103 (192.168.226.103)' can't be established.
#ECDSA key fingerprint is SHA256:LnDY/uP4vLhPN1Ufr0KpFWKCy2XBxVtLR7nKU6Kw+z8.
#ECDSA key fingerprint is MD5:f3:02:37:7f:e0:76:92:ac:67:4f:88:9d:e8:2f:40:d2.
#Are you sure you want to continue connecting (yes/no)? yes
#Warning: Permanently added 'hadoop103,192.168.226.103' (ECDSA) to the list of known hosts.
#root@hadoop103's password:
#hosts 100% 236 275.8KB/s 00:00
网络命令
#centos7 minimal中不带,需手动安装
yum install net-tools -y
#查看当前网卡信息
ifconfig
#查看核心路由表
netstat -r
#Kernel IP routing table
#Destination Gateway Genmask Flags MSS Window irtt Iface
#default gateway 0.0.0.0 UG 0 0 0 ens33
#192.168.226.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
#查看端口占用情况
netstat -anp
#查看ip是否连通
ping hadoop102
#查看端口是否连通
yum install telnet -y
telnet hadoop102 22
#Trying 192.168.226.102...
#Connected to hadoop102.
#Escape character is '^]'.
#SSH-2.0-OpenSSH_7.4
#
#Protocol mismatch.
#Connection closed by foreign host.
#restful接口访问
curl -XGET https://www.baidu.com