|
|
|
|
# 一、文件
|
|
|
|
|
## 1.1 压缩及解压
|
|
|
|
|
+ zip
|
|
|
|
|
```shell
|
|
|
|
|
# 压缩
|
|
|
|
|
zip -r ./xxx.zip ./*
|
|
|
|
|
# 解压
|
|
|
|
|
unzip xxx.zip
|
|
|
|
|
# 查看压缩文件内容
|
|
|
|
|
unzip -v xxx.zip
|
|
|
|
|
# 从zip中删除xxx.txt文件
|
|
|
|
|
zip xxx.zip -d xxx.txt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
+ tar
|
|
|
|
|
```shell
|
|
|
|
|
# 解压
|
|
|
|
|
tar -zxvf xxxx.tar.gz
|
|
|
|
|
tar -xvf xxxx.tar
|
|
|
|
|
tar -xjvf xxxx.tar.bz2
|
|
|
|
|
|
|
|
|
|
# 压缩
|
|
|
|
|
# 将目录里所有jpg文件打包成tar.jpg
|
|
|
|
|
tar -cvf jpg.tar *.jpg
|
|
|
|
|
# 将目录里所有jpg文件打包成jpg.tar后,并且将其用gzip压缩
|
|
|
|
|
tar -czf jpg.tar.gz *.jpg
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
+ 压缩命令过长
|
|
|
|
|
```shell
|
|
|
|
|
find ./ -name '*' -print |zip files -@
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 1.2 文件合并及切分
|
|
|
|
|
+ 合并
|
|
|
|
|
```shell
|
|
|
|
|
cat *.txt > target.txt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
+ 拆分
|
|
|
|
|
```shell
|
|
|
|
|
# 按大小切分
|
|
|
|
|
split -b 100m xxxx
|
|
|
|
|
# 按行切分
|
|
|
|
|
split -l xxxx
|
|
|
|
|
# 设置拆分后文件名,指定数字后缀
|
|
|
|
|
split -b 100m -d xxxx xxxx_part_
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 1.3 查看文件
|
|
|
|
|
+ 文件大小
|
|
|
|
|
```shell
|
|
|
|
|
du -sh xxx
|
|
|
|
|
```
|
|
|
|
|
+ ls
|
|
|
|
|
```
|
|
|
|
|
# 查看所有
|
|
|
|
|
ls -a
|
|
|
|
|
# 列表形式显示
|
|
|
|
|
ls -l
|
|
|
|
|
```
|
|
|
|
|
+ ll
|
|
|
|
|
```
|
|
|
|
|
# 以文件上次被修改的时间排序
|
|
|
|
|
ll -lht|head -n 20
|
|
|
|
|
```
|
|
|
|
|
## 1.4 创建文件
|
|
|
|
|
```
|
|
|
|
|
# 创建文件
|
|
|
|
|
touch xxx.txt
|
|
|
|
|
# 创建隐藏文件
|
|
|
|
|
touch .xxxx.txt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 1.5 移动及复制文件(夹)
|
|
|
|
|
```shell
|
|
|
|
|
# 将xxx.txt文件移动到abc文件夹
|
|
|
|
|
mv xxx.txt abc
|
|
|
|
|
# 将1文件移动到2文件,实质上就是1文件重命名为2文件
|
|
|
|
|
mv 1.txt 2.txt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# 使用指令 cp 将当前目录 test/ 下的所有文件复制到新目录 newtest 下
|
|
|
|
|
cp –r test/ newtest
|
|
|
|
|
# cp 命令使用 -r 参数可以将 packageA 下的所有文件拷贝到 packageB
|
|
|
|
|
cp -r /home/packageA/* /home/cp/packageB/
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 1.6 查找文件
|
|
|
|
|
+ find
|
|
|
|
|
```
|
|
|
|
|
# 指定目录
|
|
|
|
|
find /home -name 123.txt
|
|
|
|
|
# 模糊查找12开头的文件
|
|
|
|
|
find /home -name ‘12*’
|
|
|
|
|
# 将当前目录及其子目录下所有文件后缀为 .c 的文件列出来
|
|
|
|
|
find . -name "*.c"
|
|
|
|
|
# 将当前目录及其子目录中的所有文件列出
|
|
|
|
|
find . -type f
|
|
|
|
|
# 全局查找以txt后缀文件
|
|
|
|
|
find / -name "*.txt*"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 1.7 查看文件
|
|
|
|
|
+ view
|
|
|
|
|
```shell
|
|
|
|
|
# 进入vi查看,不可编辑
|
|
|
|
|
view xxx.txt
|
|
|
|
|
```
|
|
|
|
|
+ cat
|
|
|
|
|
```
|
|
|
|
|
# 输出文件
|
|
|
|
|
cat xxx.txt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 1.8 清空文件
|
|
|
|
|
+ true
|
|
|
|
|
```shell
|
|
|
|
|
true > 1.txt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 1.9 将结果转存文件
|
|
|
|
|
```
|
|
|
|
|
# 将内容追加到txt中
|
|
|
|
|
ls > 1.txt
|
|
|
|
|
ll > 1.txt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 1.10 grep
|
|
|
|
|
```shell
|
|
|
|
|
# 查找进程
|
|
|
|
|
ps -ef|grep xxxx
|
|
|
|
|
#
|
|
|
|
|
```
|
|
|
|
|
## 1.11 sed
|
|
|
|
|
|
|
|
|
|
## 1.12 awk
|
|
|
|
|
|
|
|
|
|
# 二、网络
|
|
|
|
|
## 2.1 查看IP
|
|
|
|
|
yum install -y net-tools
|
|
|
|
|
+ ifconfig
|
|
|
|
|
```
|
|
|
|
|
ifconfig
|
|
|
|
|
```
|
|
|
|
|
+ lsof
|
|
|
|
|
```
|
|
|
|
|
# 查看所有
|
|
|
|
|
lsof -i
|
|
|
|
|
# 查看指定端口
|
|
|
|
|
lsof -i:8080
|
|
|
|
|
# 查看文件进程
|
|
|
|
|
lsof xxx.txt
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
+ ip
|
|
|
|
|
```
|
|
|
|
|
ip link show # 显示网络接口信息
|
|
|
|
|
ip link set eth0 up # 开启网卡
|
|
|
|
|
ip link set eth0 down # 关闭网卡
|
|
|
|
|
ip link set eth0 promisc on # 开启网卡的混合模式
|
|
|
|
|
ip link set eth0 promisc offi # 关闭网卡的混个模式
|
|
|
|
|
ip link set eth0 txqueuelen 1200 # 设置网卡队列长度
|
|
|
|
|
ip link set eth0 mtu 1400 # 设置网卡最大传输单元
|
|
|
|
|
ip addr show # 显示网卡IP信息
|
|
|
|
|
ip addr add 192.168.0.1/24 dev eth0 # 设置eth0网卡IP地址192.168.0.1
|
|
|
|
|
ip addr del 192.168.0.1/24 dev eth0 # 删除eth0网卡IP地址
|
|
|
|
|
|
|
|
|
|
ip route show # 显示系统路由
|
|
|
|
|
ip route add default via 192.168.1.254 # 设置系统默认路由
|
|
|
|
|
ip route list # 查看路由信息
|
|
|
|
|
ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # 设置192.168.4.0网段的网关为192.168.0.254,数据走eth0接口
|
|
|
|
|
ip route add default via 192.168.0.254 dev eth0 # 设置默认网关为192.168.0.254
|
|
|
|
|
ip route del 192.168.4.0/24 # 删除192.168.4.0网段的网关
|
|
|
|
|
ip route del default # 删除默认路由
|
|
|
|
|
ip route delete 192.168.1.0/24 dev eth0 # 删除路由
|
|
|
|
|
```
|
|
|
|
|
## 2.2 查看网关
|
|
|
|
|
```
|
|
|
|
|
# 查看gateway
|
|
|
|
|
route -n
|
|
|
|
|
```
|
|
|
|
|
## 2.3 查看端口占用
|
|
|
|
|
```
|
|
|
|
|
netstat -anp|grep 3306
|
|
|
|
|
```
|
|
|
|
|
## 2.4 ping
|
|
|
|
|
```shell
|
|
|
|
|
ping 192.168.1.1
|
|
|
|
|
```
|
|
|
|
|
## 2.5 host
|
|
|
|
|
+ hostname
|
|
|
|
|
```
|
|
|
|
|
# 查看本机Hostname
|
|
|
|
|
hostname
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 查看Hosts文件
|
|
|
|
|
vi /etc/hosts
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 2.6 SSH远程登录
|
|
|
|
|
```
|
|
|
|
|
# 默认端口22
|
|
|
|
|
ssh username@ip
|
|
|
|
|
# 指定端口
|
|
|
|
|
ssh -p 2233 username@ip
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 2.7 SCP远程复制
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
# 指定用户名IP
|
|
|
|
|
scp local_file remote_username@remote_ip:remote_folder
|
|
|
|
|
或者
|
|
|
|
|
scp local_file remote_username@remote_ip:remote_file
|
|
|
|
|
或者
|
|
|
|
|
# 做了互信
|
|
|
|
|
scp local_file remote_ip:remote_folder
|
|
|
|
|
或者
|
|
|
|
|
scp local_file remote_ip:remote_file
|
|
|
|
|
scp local_file remote_host:remote_file
|
|
|
|
|
# 递归复制整个目录
|
|
|
|
|
scp -r local_dir remote_host:remote_folder
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 2.8 查看网卡
|
|
|
|
|
查看当前使用网卡
|
|
|
|
|
```
|
|
|
|
|
nmcli d
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
修改IP,添加DNS
|
|
|
|
|
```text
|
|
|
|
|
nmcli c m ens33 ipv4.address 192.168.80.10/24 # 修改 IP 地址和子网掩码
|
|
|
|
|
nmcli c m ens33 ipv4.method manual # 修改为静态配置,默认是 auto
|
|
|
|
|
nmcli c m ens33 ipv4.gateway 192.168.80.2 # 修改默认网关
|
|
|
|
|
nmcli c m ens33 ipv4.dns 192.168.80.2 # 修改 DNS
|
|
|
|
|
nmcli c m ens33 +ipv4.dns 114.114.114.114 # 添加一个 DNS
|
|
|
|
|
nmcli c m ens33 ipv6.method ignored # 将 IPv6 禁用,针对CentOS8,三个可选项:disabled、auto、manual
|
|
|
|
|
nmcli c m ens33 connection.autoconnect yes # 开机启动
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
显示连接信息
|
|
|
|
|
```
|
|
|
|
|
nmcli connection show
|
|
|
|
|
或
|
|
|
|
|
nmcli c show
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 2.9 安装SSH
|
|
|
|
|
```shell
|
|
|
|
|
yum -y install openssh openssh-server openssh-clients
|
|
|
|
|
systemctl start sshd
|
|
|
|
|
systemctl status sshd
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 2.10 修改DNS
|
|
|
|
|
```
|
|
|
|
|
vim /etc/resolv.conf
|
|
|
|
|
# 重启网络
|
|
|
|
|
systemctl start network.service
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 2.11 网络测试
|
|
|
|
|
```shell
|
|
|
|
|
# 返回0表示正常
|
|
|
|
|
wget --spider -T 5 -q -t 2 www.baidu.com | echo $?
|
|
|
|
|
```
|
|
|
|
|
# 三、权限
|
|
|
|
|
## 3.1 用户权限及用户组
|
|
|
|
|
Linux/Unix 的文件调用权限分为三级 : 文件所有者(Owner)、用户组(Group)、其它用户(Other Users)
|
|
|
|
|
+ chmod
|
|
|
|
|
```
|
|
|
|
|
# 添加操作权限
|
|
|
|
|
chmod +x xxx.sh
|
|
|
|
|
#
|
|
|
|
|
chmod 777 xxx.sh
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![[file-permissions-rwx.jpg]]![[rwx-standard-unix-permission-bits.png]]
|
|
|
|
|
+ chown
|
|
|
|
|
```
|
|
|
|
|
# 添加操作用户
|
|
|
|
|
chown [-R] 所有者:所属组 文件或目录
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 3.2 免密
|
|
|
|
|
```
|
|
|
|
|
# 安装ssh
|
|
|
|
|
yum -y install openssh openssh-server openssh-clients
|
|
|
|
|
systemctl start sshd
|
|
|
|
|
systemctl status sshd
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
ssh-keygen -t rsa #三次回车
|
|
|
|
|
# 复制rsa凭证到对方机cdh-master在hosts中配置,也可以改为 用户名@ip
|
|
|
|
|
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cdh-master
|
|
|
|
|
ssh-copy-id -f -i ~/.ssh/id_rsa.pub cdh-slave1
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 四、系统
|
|
|
|
|
## 4.1 系统时间
|
|
|
|
|
```
|
|
|
|
|
date
|
|
|
|
|
```
|
|
|
|
|
## 4.2 防火墙
|
|
|
|
|
```
|
|
|
|
|
systemctl disable firewalld
|
|
|
|
|
systemctl stop firewalld
|
|
|
|
|
```
|
|
|
|
|
## 4.3 selinux
|
|
|
|
|
```
|
|
|
|
|
[root@dev-server ~]# getenforce
|
|
|
|
|
Disabled
|
|
|
|
|
[root@dev-server ~]# /usr/sbin/sestatus -v
|
|
|
|
|
SELinux status: disabled
|
|
|
|
|
```
|
|
|
|
|
临时关闭
|
|
|
|
|
```
|
|
|
|
|
##设置SELinux 成为permissive模式
|
|
|
|
|
##setenforce 1 设置SELinux 成为enforcing模式
|
|
|
|
|
setenforce 0
|
|
|
|
|
```
|
|
|
|
|
永久关闭
|
|
|
|
|
```
|
|
|
|
|
vi /etc/selinux/config
|
|
|
|
|
# 将SELINUX=enforcing改为SELINUX=disabled
|
|
|
|
|
# 设置后需要重启才能生效
|
|
|
|
|
```
|
|
|
|
|
## 4.4 linux内核及版本
|
|
|
|
|
+ lsb_release
|
|
|
|
|
```
|
|
|
|
|
# 查看发行版
|
|
|
|
|
lsb_release -a
|
|
|
|
|
```
|
|
|
|
|
+ uname
|
|
|
|
|
```
|
|
|
|
|
# 查看内核版本
|
|
|
|
|
uname -a
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 4.5 查看内存、CPU
|
|
|
|
|
+ free 查看内存
|
|
|
|
|
```shell
|
|
|
|
|
# 以G为单位
|
|
|
|
|
free -h
|
|
|
|
|
# 以M为单位
|
|
|
|
|
free -m
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
CPU
|
|
|
|
|
```
|
|
|
|
|
# 查看CPU型号及总线程数
|
|
|
|
|
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
|
|
|
|
|
# 查看CPU线程数
|
|
|
|
|
cat /proc/cpuinfo |grep "processor"|wc -l
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 4.6 修改密码
|
|
|
|
|
```
|
|
|
|
|
# 修改root密码
|
|
|
|
|
passwd root
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 4.7 查看磁盘
|
|
|
|
|
```shell
|
|
|
|
|
df -h
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 4.8 查看进程
|
|
|
|
|
+ jps
|
|
|
|
|
```
|
|
|
|
|
查看java虚拟机进程
|
|
|
|
|
jsp
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 4.9 软链接
|
|
|
|
|
将python2.7.9映射为python,可以先用whereis python或者which python查找位置
|
|
|
|
|
```shell
|
|
|
|
|
ln -s /usr/local/python-2.7.9/bin/python /usr/bin/python
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 4.10 查看上次登录
|
|
|
|
|
```shell
|
|
|
|
|
who -b
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 4.11 配置定时任务
|
|
|
|
|
hadoop任务可能不会执行,因为crontab的path和系统path不一致,找到hadoop命令。如果出现找不到命令情况请添加cron path
|
|
|
|
|
```shell
|
|
|
|
|
root 用户
|
|
|
|
|
vim /etc/crontab
|
|
|
|
|
|
|
|
|
|
SHELL=/bin/bash
|
|
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|
|
|
|
MAILTO=root
|
|
|
|
|
|
|
|
|
|
# For details see man 4 crontabs
|
|
|
|
|
|
|
|
|
|
# Example of job definition:
|
|
|
|
|
# .---------------- minute (0 - 59)
|
|
|
|
|
# | .------------- hour (0 - 23)
|
|
|
|
|
# | | .---------- day of month (1 - 31)
|
|
|
|
|
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
|
|
|
|
|
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
|
|
|
|
|
# | | | | |
|
|
|
|
|
# * * * * * user-name command to be executed
|
|
|
|
|
20 04 * * * root reboot
|
|
|
|
|
|
|
|
|
|
# 加载配置
|
|
|
|
|
crontab /etc/crontab
|
|
|
|
|
|
|
|
|
|
# 重启crontab服务
|
|
|
|
|
systemctl restart crond.service
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 4.12 centos 防火墙
|
|
|
|
|
```shell
|
|
|
|
|
# 查看防火墙所有开放的端口
|
|
|
|
|
firewall-cmd --zone=public --list-ports
|
|
|
|
|
# 查看防火墙状态
|
|
|
|
|
firewall-cmd --state
|
|
|
|
|
# 开放端口
|
|
|
|
|
firewall-cmd --zone=public --add-port=5672/tcp --permanent
|
|
|
|
|
# 关闭端口
|
|
|
|
|
firewall-cmd --zone=public --remove-port=5672/tcp --permanent
|
|
|
|
|
# 配置立即生效
|
|
|
|
|
firewall-cmd --reload
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 五、vim
|
|
|
|
|
![[vi-vim-cheat-sheet-sch.gif]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 操作 | 命令 |
|
|
|
|
|
| -------------- | ------------------------------- |
|
|
|
|
|
| 复制 | yy 复制当前行 |
|
|
|
|
|
| 粘贴 | p |
|
|
|
|
|
| 查找 | 普通模式下 按下/ 并输入待查字符 |
|
|
|
|
|
| 保存/强制保存 | wq/wq! |
|
|
|
|
|
| 退出vim | q/q! |
|
|
|
|
|
| 取消插入模式 | esc |
|
|
|
|
|
| 显示/取消行号 | :set nu/:set nonu |
|
|
|
|
|
| 修改文件format | :set fileformat=unix |
|
|
|
|
|
| 删除 | dd 删除当前行 |
|
|
|
|
|
| 方向键 | h:左 j:下 k:上 l:右 |
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 全局查找替换
|
|
|
|
|
:%s/查找字符串/替换字符串/g
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# 六、环境变量
|
|
|
|
|
## 6.1 java 环境变量
|
|
|
|
|
```shell
|
|
|
|
|
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
|
|
|
|
|
export PATH=$JAVA_HOME/bin:$PATH
|
|
|
|
|
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
|
|
|
|
|
source ~/.bashrc
|
|
|
|
|
# 验证
|
|
|
|
|
java -version
|
|
|
|
|
echo $JAVA_HOME
|
|
|
|
|
```
|