
Others
-
获取公网IP
- curl ifconfig.me
-
磁盘空间
- df -hl 查看磁盘剩余空间
- df -h 查看每个根路径的分区大小
- du -sh [目录名] 返回该目录的大小
- du -sm [文件夹] 返回该文件夹总M数
- du -h [目录名] 查看指定文件夹下的所有文件大小(包含子文件夹)
-
make
- 通过外部编译器的,比如linux中的gcc集来编译源码
- 获取Makefile文件的命令触发编译
-
curl
- -X GET/POST
- -I 获取head
- curl有cache
-
查看tcp/udp端口
- netstat -tunlp
- sudo su - && lsof -i:8080
-
查看系统启动时间
- who -b
- date -d "$(awk -F. '{print $1}' /proc/uptime) second ago" +"%Y-%m-%d %H:%M:%S"
-
查看进程的启动时间
- ps -p PID -o lstart
-
查看cpu
- sar -u 1 5 每1秒采集一次,共5次
- top
-
查看进程占用内存
- cat /proc/27930/status
- ps -e -o 'pid,args,rsz,uid,user,cmd' | sort -nrk3 | less
-
查看进程个数
- ps -ef | wc -l
-
查看进程个数限制
- ulimit -a
-
查看ip
- hostname -i
- ifconfig
-
查看环境变量
- export
-
查看目录大小 :
- du -sh * | grep G | sort -nr
- du -s * | sort -nr
- du -h . 列出子目录
- du -sh * 不列出子目录
- df -h . 列出总量和使用情况
-
压缩/解压缩
- tar
- 解压 tar -xzvf xx.tar.gz
- -c : 建立压缩档案
- -x:解压
- -f : 文件名字,切记,这个参数是最后一个参数,后面只能文件名。
- -z:有gzip属性的 gz
- -v:显示所有过程
- unzip x.zip/x.jar . : 解压缩
- tar
-
查看系统内核
- uname -a
-
获取RedHat版本
- cat /etc/redhat-release
1>/dev/null 2>&1的含义
代表重定向到哪里,例如:echo "123" > /home/123.txt
- 1 表示stdout标准输出,系统默认值是1,所以">/dev/null"等同于"1>/dev/null"
- 2 表示stderr标准错误
- & 表示等同于的意思,2>&1,表示2的输出重定向等同于1
- /dev/null,或称空设备,是一个特殊的设备文件,它丢弃一切写入其中的数据(但报告写入操作成功)
- 这句话等同于1>/dev/null 2>/dev/null 含义是将标准输入和输出丢弃
-
遍历目录下文件
for file in *
do
if [ -d "$file" ]
then
echo "a forder"
else if [ -f "$file" ]
then
echo "a file"
fi
done 获取当前shell的路径: basepath=$(cd
dirname $0
; pwd)字符串替换: sed -i "s/aaa/bbb/g" test.txt
find .|xargs grep -ri "IBM" : 查找字符在哪个文件
alias aName='xxx'
grep -A/-B 10 'XXX' XX.log: 带上grep语句后/前 10条
less -N: 显示行号
history 10: 察看前10条历史命令
chmod -R 777 folder: 赋权限
free -m -o | grep 'Mem' | awk '{print $4}': 查看服务器空间
crontab -e: 进入CRON JOB VI模式
ps -e -o 'pid,comm,args,pcpu,rsz,vsz,stime,user,uid' | grep oracle | sort -nrk5: 查看进程
ps -ef | awk '{print $2}' | xargs kill -9: kill进程
:set ff=unix: vi 模式下将文件格式转换成unix,可以解决windows下shell脚本和Liunx格式不一样问题
-
awk
- echo abcde | awk '{print substr($0, 0, 2)}'
- ps -e -o 'cmd' | awk '{print substr($0,index($0,"'$APP_HOME'"),20)}'
- CURRENT_DATE=
date
ps -e -o 'rsz,cmd' | awk '{print $1, "'"$CURRENT_DATE"'"}'awk引用外部变量
nohup sh process_monitor.sh > process_monitor.out & : 后台持续启动脚本
find /xx/xx/ -name 'xx*.log': 查找文件
find /xx/xx/ -name 'xx*.log' | grep -v 'xxx' | xargs ls -l: find 和 ls 和用
wc *.out: 显示二进制文件的行数
Centos系统
CentOS 7系统安装
- 官网下载DVD版本的iso镜像文件
- 官网下载UltraIOS,将iso文件写入U盘,制作成为U盘启动盘
- 通过BIOS设置从U盘载入,重启
- 教程: https://www.augsky/599.html
系统版本
- Centos操作系统版本
- cat /etc/redhat-release
- Linux内核版本
- uname -a
使用鼠标
- yum install gpm
- service gpm start
基本操作
- 关机 : poweroff
- 重启 : reboot
- 待机/挂起 : systemctl suspend
- 休眠 : systemctl hibernate
笔记本关闭盖子不待机,只锁屏
- vi /etc/systemd/logind.conf
- 配置详解
- HandlePowerKey : 按下电源键后会触发的行为
- HandleSuspendKey : 按下挂起键后会触发的行为
- HandleHibernateKey : 按下休眠键后会触发的行为
- HandleLidSwitch : 关闭笔记本盖子后会触发的行为
- 行为
- ignore、poweroff、reboot、suspend、hibernate、hybrid-sleep、lock 以及 halt, kexec
- HandleLidSwitch=lock : 关闭盖子锁屏
用户与权限
User
- whoami :查看当前登录用户名
- su user:切换用户,exit回到上个用户
- cat /etc/passwd |cut -f 1 -d : : 查看用户
- useradd name :添加用户
- -g:指定用户所属的群组。值可以使组名也可以是GID。用户组必须已经存在的,期默认值为100,即users。
- -N:取消建立以用户名称为名的群组。默然group是 users
- -Umr: 创建同名组,home目录,系统用户
- userdel user: 删除用户
- 删除用户会删除默然同名组
- 删除用户后用户文件属于user id,比如1000,当创建下个用户时user id会被占用,用户文件会属于新建的用户
- -r : 同时删除home和mail
- passwd user passwd :设置密码
- usermod : 修改用户
- -G :将用户添加进组
- -g : 将用户修改为属于组
Group
- groups
- 查看当前登录用户组
- groups jude查看jude用户所在的组
- groupadd/groupdel/groupmod
权限
- which yum
- 查看yum命令的路径,然后可以看到所有者和权限
sudo : /etc/sudoers
-
命令
- sudo -l
- visudo
- man sudo
-
别名类型(Alias_Type):别名类型包括如下四种
- Host_Alias 定义主机别名;
- User_Alias 用户别名,别名成员可以是用户,用户组(前面要加%号)
- Runas_Alias 用来定义runas别名,这个别名指定的是“目的用户”,即sudo 允许切换至的用户;
- Cmnd_Alias 定义命令别名;
-
别名规则定义格式如下:
- Alias_Type NAME = item1, item2
- Alias_Type NAME = ALL
-
授权规则
- 授权用户 主机=命令动作
- jude ALL=(root)/bin/chmod,/bin/chmod
- 可以在任何可能出现的主机名的主机中,可以切换到root下执行 /bin/chown ,可以切换到任何用户招执行/bin/chmod 命令
- jude ALL= NOPASSWD: /bin/chown,/bin/chmod
- 不需要输入 用户的密码执行chown,但是执行chmod 要输入自己的密码
- !表示排除
- 授权规则3项都可以用别名代替
软件安装
wget
- 后台自动下载网络资源
- 安装 : yum install wget
- wget基本命令
- wget http://xxx.rpm
- wget -i xxx.txt : 批量下载
- wget -r -np -nd http://xxx/download
- --accept rmp : 只下载.rpm文件
- -c : 断点续传
- -P : 指定目录
apt
- apt-get update : 更新apt
- apt-get install vim : 可以在docker容器中安装vi
- sudo apt install yum : ubuntu安装yum
YUM
- yum基本概念
- 基於RPM包管理,能够从指定的服务器自动下载RPM包并且安装
- 可以自动处理依赖性关系,并且一次安装所有依赖的软体包
- yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令
- yum源
- 默认源配置目录 : /etc/yum.repos.d/
- 配置里面所有enabled=1的(默认)源
- 命令
- yum repolist 查看当前可用源
- yum grouplist:显示包组
- yum list {available|installed|updates} :显示包列表
- yum list vsftpd* 显示和vsftpd匹配的列表
- 除了支持远程仓库源,还支持本地挂载目录和远程挂载目录
- yum-config-manager
- 安装:yum install -y yum-utils
- yum-config-manager --add-repo xxx.repo
- yum-config-manager --enable docker-ce-edge : 相当于手动将enabled=0
- yum-config-manager --disable docker-ce-edge
- EPEL源
- 更丰富的,高质量的,更新的yum源
- yum search epel安装
- rpm下载安装
- 阿里巴巴开源镜像站
- 其他yum源设置disabled=0
- Docker源
- yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- yum命令选项
- --nogpgcheck:禁止进行gpgcheck
- -y: 自动回答为“yes”
- -q:静默模式
- --disablerepo=repoidglob:临时禁用此处指定的repo
- --enablerepo=repoidglob:临时启用此处指定的repo
- --noplugins:禁用所有插件
- yum安装卸载
- yum install/groupinstall package
- yum install package-version 安装指定版本
- yum restall package:重做
- yum update package:更新包
- yum check-update
- yum remove package1 [package2]
- yum install/groupinstall package
- yum查询
- yum search xxx :搜索带有某个关键字的安装包
- yum info 查看search到的程序包信息
- yum list package --showduplicates : 查看所有版本
- yum list installed : 查看所有已安装的package
RPM
- rpm命令
- 安装 rpm -ivh --prefix=$path XX.rpm
- 查看 rpm -qa XX
- 查看安装的文件 rpm -ql XX
- 卸载 rpm -e --nodeps 察看得到的包名字
gcc编译源码
命令安装路径
- which less
网络设置
CentOS连接WIFI
- 检查无线网卡/网口
- dmesg | grep firmware
- iw dev : Interface后的是网口名,这里是wlp3s0
- 激活无线网口
- ip link set wlp3s0 up
- ip a: BROADCAST,MULTICAST,UP,LOWER_UP中的UP代表激活
- 安装NetworkManager
- nmcli d status : 如果wlp3s0的status是unmanaged,说明没有NetworkManager
- yum install NetworkManager-wifi
- systemctl restart NetworkManager
- wifi操作
- nmcli r wifi on/off : 打开/关闭wifi功能
- nmcli d wifi : 查找wifi
- nmcli c: 查看已经连接的wifi
- nmcli c up/down/delete Jude : 连接/关闭/删除已设置过的wifi
- nmcli --ask d wifi connect Jude : 连接wifi Jude,输入密码
- error connection activation failed (7) secrets were required but not provided : 重启电脑
Linux连接WIFI
- 检查无线网络连接情况
- iw wlp3s0 link
- 扫描可连接的wifi
- iw wlp3s0 scan | grep SSID
- 连接指定的SSID
- wpa_supplicant -B -i wlp3s0 -c <(wpa_passphrase "[SSID]" "[PIN]")
- 用dhcp 获得 IP 分配
- dhclient [name]
- 测试是否成功地从路由器获取了ip
- ip a show [name]
与windows组成局域网
- 需要linux与windows拥有相同的子网掩码,相同的网关,同段位ip
- 可以通过连接到相同的猫
- 连接到相同的路由器
- 同处于一个wifi
- windows在Internate选项的网络共享里,需要开启网络发现和文件共享,linux才可以ping通windows
putty连接SSH
- 打开centos的SSH服务
- service sshd start
- 下载putty连接局域网ip
alias for gradle and git
-
alias
unalias -a alias build="disableCB && gradle ktlintformat clean build && enableCB"
alias branch="git branch -vv && git cherry -v"
alias push="~/jude/alias_job.sh push_branch push"
alias fast_commit_push="~/jude/alias_job.sh fast_commit_push"
alias merge_develop="git merge origin/develop"
alias develop_branch="git checkout develop && git pull && branch"
alias show_all_branch="~/jude/alias_job.sh show_all_branch" alias bbset_branch="~/jude/alias_job.sh set_current_branch"
alias bbcreate_all_branch="~/jude/alias_job.sh create_all_branch"
alias bbpush_branch="~/jude/alias_job.sh push_branch push_new" alias ccbuild="ccenable && gradle ktlintformat clean build"
alias ccenable="gradle enableCompositeBuild"
alias ccdisable="gradle disableCompositeBuild"
alias bbnew_branch="git pull && git checkout origin/develop -b `cat ~/jude/current_branch` && git branch --unset-upstream && branch"
alias bbdelete_branch="~/jude/alias_job.sh delete_current_branch"
alias bbresert_hard="~/jude/alias_job.sh hard_reset" alias aaa="cat ~/.bash_profile"
alias eee="vi ~/.bash_profile"
alias rrr="source ~/.bash_profile"
alias la="ls -tral"
alias ll="ls -trl"
alias killjava="ps -ef | grep java | grep -v grep | awk '{print $2}' | xargs kill -9" -
alias job
#!/bin/bash set_current_branch() {
echo $1 > ~/jude/current_branch
cat ~/jude/current_branch
} hard_reset() {
read -r -p "Git Hard Reset your local change? [Y/n] : " input case $input in
[Y])
git reset --hard
;;
*)
echo "do nothing"
exit 1
;;
esac
} delete_current_branch() {
read -r -p "Delete current branch `cat ~/jude/current_branch`? [Y/n] : " input case $input in
[Y])
git checkout develop && git branch -d `cat ~/jude/current_branch` && git branch -vv
;;
*)
echo "do nothing"
exit 1
;;
esac
} fast_commit_push() {
git branch -vv && git status read -r -p "Commit and push branch `cat ~/jude/current_branch`? [Y/n] : " input case $input in
[Y])
branch=`cat ~/jude/current_branch`
git commit -m $branch -a
push_branch push
;;
*)
echo "do nothing"
exit 1
;;
esac
} push_branch() {
case $1 in
"push_new")
git push --set-upstream origin `cat ~/jude/current_branch` && git branch -vv && git cherry -v
;;
"push")
git pull && git push && git branch -vv && git cherry -v
;;
*)
echo "do nothing"
exit 1
;;
esac
current=`pwd`
branch=`cat ~/jude/current_branch`
case $current in
"/Users/jude.sheng/IdeaProjects/paymentacceptance-adaptor")
open https://github.com/airwallex/paymentacceptance-adaptor/compare/develop...$branch?expand=1
;;
"/Users/jude.sheng/IdeaProjects/paymentacceptance-executor")
open https://github.com/airwallex/paymentacceptance-executor/compare/develop...$branch?expand=1
;;
"/Users/jude.sheng/IdeaProjects/paymentacceptance-core")
open https://github.com/airwallex/paymentacceptance-core/compare/develop...$branch?expand=1
;;
"/Users/jude.sheng/IdeaProjects/paymentacceptance-gateway")
open https://github.com/airwallex/paymentacceptance-gateway/compare/develop...$branch?expand=1
;;
"/Users/jude.sheng/IdeaProjects/paymentacceptance-tokenservice")
open https://github.com/airwallex/paymentacceptance-tokenservice/compare/develop...$branch?expand=1
;;
"/Users/jude.sheng/IdeaProjects/paymentacceptance-common")
open https://github.com/airwallex/paymentacceptance-common/compare/develop...$branch?expand=1
;;
*)
echo "do nothing"
exit 1
;;
esac
} create_all_branch() {
current=`pwd`
cd /Users/jude.sheng/IdeaProjects
cd paymentacceptance-adaptor
pwd && git pull && git checkout origin/develop -b `cat ~/jude/current_branch` && git branch --unset-upstream
cd ../paymentacceptance-common
pwd && git pull && git checkout origin/develop -b `cat ~/jude/current_branch` && git branch --unset-upstream
cd ../paymentacceptance-executor
pwd && git pull && git checkout origin/develop -b `cat ~/jude/current_branch` && git branch --unset-upstream
cd ../paymentacceptance-core
pwd && git pull && git checkout origin/develop -b `cat ~/jude/current_branch` && git branch --unset-upstream
cd ../paymentacceptance-gateway
pwd && git pull && git checkout origin/develop -b `cat ~/jude/current_branch` && git branch --unset-upstream
cd ../paymentacceptance-tokenservice
pwd && git pull && git checkout origin/develop -b `cat ~/jude/current_branch` && git branch --unset-upstream cd /Users/jude.sheng/IdeaProjects
cd paymentacceptance-adaptor
git branch -vv
cd ../paymentacceptance-common
git branch -vv
cd ../paymentacceptance-executor
git branch -vv
cd ../paymentacceptance-core
git branch -vv
cd ../paymentacceptance-gateway
git branch -vv
cd ../paymentacceptance-tokenservice
git branch -vv cd $current
} show_all_branch() {
current=`pwd`
cd /Users/jude.sheng/IdeaProjects
cd paymentacceptance-adaptor
echo "=============================" && pwd && git status && echo "----------------------" && cherry -v
cd ../paymentacceptance-common
echo "=============================" && pwd && git status && echo "----------------------" && cherry -v
cd ../paymentacceptance-executor
echo "=============================" && pwd && git status && echo "----------------------" && cherry -v
cd ../paymentacceptance-core
echo "=============================" && pwd && git status && echo "----------------------" && cherry -v
cd ../paymentacceptance-gateway
echo "=============================" && pwd && git status && echo "----------------------" && cherry -v
cd ../paymentacceptance-tokenservice
echo "=============================" && pwd && git status && echo "----------------------" && cherry -v
cd $current
} case $1 in
"set_current_branch")
set_current_branch $2
;;
"hard_reset")
hard_reset
;;
"delete_current_branch")
delete_current_branch
;;
"create_all_branch")
create_all_branch
;;
"push_branch")
push_branch $2
;;
"fast_commit_push")
fast_commit_push
;;
"show_all_branch")
show_all_branch
;;
*)
echo "do nothing"
exit 1
;;
esac