Last active
December 28, 2018 04:00
-
-
Save bluesmilery/a893817a4c058684ac6c2379ce772d36 to your computer and use it in GitHub Desktop.
shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 获取当前系统时间 | |
date "+%Y-%m-%d %H:%M:%S" | |
# 查看CentOS系统版本 | |
cat /etc/redhat-release | |
# 查看Linux系统版本(更通用) | |
cat /etc/issue | |
# 查看内核版本 | |
uname -r | |
# awk eg. | |
awk -F "\t" '{print $1}' dup | uniq -c | awk '{if ($1>4) print $2}' | |
awk -F '\t' 'NR>1 {print $26}' $FILE_PATH | sort -u | |
awk -F '\t' -v var=$city 'NR>1 {if($26==var) print}' $FILE_PATH > $SUB_FILE_PATH | |
awk -F '\t' '{$10=null;print $0}' | |
awk '{a=$1;b=$2;c=a":"b;print c}' | |
# sed eg. | |
sed "1i\\${FILE_HEAD}" -i $SUB_FILE_PATH | |
sed 's/display_diamond_index_di.//g' | |
# 查找某进程 | |
ps -ef | grep xxx | |
# 判断文件夹是否存在 | |
if [ ! -d "$folder"]; then | |
mkdir "$folder" | |
fi | |
# 判断文件是否存在:-f;判断文件是否存在且具有可执行权限:-x | |
if [ ! -f "$file" ]; then | |
touch "$file" | |
fi | |
# CPU占用最多的前10个进程/k3为CPU,k4为内存,k5为虚拟内存 | |
ps auxw | head -1; ps auxw | sort -rn -k3 | head -10 | |
# 杀掉一系列进程 | |
ps -ef | grep user_discovery | awk '{print $2}' | xargs kill -9 | |
# 搜索目录下所有文件下是否存在keywords | |
grep -nr keywords * | |
# 生成随机数,范围为0-32767之间的整数 | |
$RANDOM | |
# 指定范围,例如1-5 | |
$((RANDOM % 5 + 1)) | |
# break跳出2层循环 | |
break 2 | |
# yarn杀任务,例如appid为application_1536911522033_1201615 | |
yarn application -kill appid | |
# 创建多级文件夹,如果first和second不存在则会自动创建 | |
mkdir -p ./first/second/third | |
# 获取上一个命令的pid | |
$! | |
# 获取后台进程的返回值,即使已结束也可以 | |
wait xxx && echo "succeed" || echo "failed" | |
# 多列排序,先按第一列升序,再按第二列降序 | |
sort -k 1 -k 2r | |
# ls相关 | |
ls -lt # 按时间顺序显示(默认降序,如果升序再加个r) | |
ls -ls # 按文件大小顺序显示(默认降序,如果升序再加个r) | |
# 判断指定字符串是否在数组中 | |
echo ${arr[@]} | grep -wq $str && echo "yes" || echo "no" | |
# for循环数字,第一二种里面的数字不能用变量,第三种可以 | |
for i in {1..5} == for i in $(seq 1 5) == for i in 1 2 3 4 5 | |
for i in {1..5..2} == for i in $(seq 1 2 5) == for i in 1 3 5 | |
for ((i=0; i<10; i++)) | |
# 查看目前有哪些内核版本 | |
cat /boot/grub2/grub.cfg | grep menuentry | |
# 切换内核 | |
grub2-set-default "CentOS Linux (3.10.0-862.14.4.el7.x86_64) 7 (Core)" | |
# 查看当前配置的内核 | |
grub2-editenv list | |
# 内核模块相关 | |
lsmod # 显示当前已加载的模块 | |
modinfo xxx # 显示某模块的信息 | |
insmod xxx # 加载模块,xxx需为模块完整的绝对路径,并且不会解决模块依赖问题。删除为rmmod | |
modprobe -va xxx # 加载模块,xxx为模块名即可,可以解决模块依赖问题,-v显示执行的详细信息;若同时加载多个包,使用-a可以都加载,否则只加载第一个。删除为 -r | |
# 脱离依赖删除yum安装的包 | |
rpm -e --nodeps xxx | |
# 打包带权限用-p | |
tar -pcvf xxx.tar path | |
# 查看文件(或文件夹下的文件)的程序占用 | |
fuser xxx | |
lsof xxx | |
# 打包解包;加上z是gz,加上j是bz | |
tar cvf xxx.tar path # 打包 | |
tar xvf xxx.tar # 解包 | |
# Ubuntu替换阿里源 | |
sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list | |
sed -i s/security.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list | |
apt-get update | |
# 终端内创建文件内容 | |
cat <<EOF >file.name | |
xxxxxx | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment