随笔分类 - linux shell
摘要:linux系统awk命令拆分文件。 1、 [root@centos7 test2]# ls file.txt [root@centos7 test2]# cat file.txt -rw-r--r-- 1 root 52457 Aug 10 2019 ngx_http.c -rw-r--r-- 1
阅读全文
摘要:1、测试数据 测试1 [root@centos7 test2]# cat a.txt 01 02 03 04 05 06 07 08 09 10 2、测试2 [root@centos7 test2]# cat a.txt 01 02 03 04 05 06 07 08 09 10 [root@cen
阅读全文
摘要:1、测试数据,测试1 [root@centos7 test2]# seq -f %02g 10 > a.txt [root@centos7 test2]# ls a.txt [root@centos7 test2]# cat a.txt 01 02 03 04 05 06 07 08 09 10 2
阅读全文
摘要:1、测试数据 [root@centos7 test3]# cat b.txt e t s e s g m x w d g i d t e g x g e w 2、打印匹配w的行 [root@centos7 test3]# cat b.txt e t s e s g m x w d g i d t e
阅读全文
摘要:1、测试1 [root@centos7 test2]# i=0 [root@centos7 test2]# max=5 [root@centos7 test2]# while((i<max));do echo $i;((i++));done 0 1 2 3 4
阅读全文
摘要:1、测试1 [root@centos7 test2]# for ((i=1; i<=5; i++)); do echo "100"; done 100 100 100 100 100
阅读全文
摘要:1、测试1 [root@centos7 test2]# cat test.sh #!/bin/bash read -p "please input an character: " i case $i in [a-z]|[A-Z]) echo "letter!" ;; [0-9]) echo "num
阅读全文
摘要:1、隐藏光标 echo -e "\033[?25l" 2、显示光标 echo -e "\033[?25h" 来源:https://blog.csdn.net/weixin_43336281/article/details/99109789
阅读全文
摘要:1、测试1 求1-100的和 [root@centos7 test2]# cat test.sh #!/bin/bash sum=0 a=1 while [ $a -le 100 ] do let sum+=$a let a++ done echo "the sum of 1-100 is: $su
阅读全文
摘要:1、for语句 [root@centos7 test2]# cat test.sh #!/bin/bash sum=0 for i in `seq $1` do let sum+=$i done echo "the sum of 1-$1 is: $sum" [root@centos7 test2]
阅读全文
摘要:1、测试1 [root@centos7 test2]# ls a.txt [root@centos7 test2]# if [ -e a.txt ]; then echo "exist";else echo "no nxist"; fi exist [root@centos7 test2]# if
阅读全文
摘要:linux shell脚本中流程控制语句 if、for、while、case 1、if语句 [root@centos7 test2]# ls test.sh [root@centos7 test2]# pwd /home/test2 [root@centos7 test2]# cat test.sh
阅读全文
摘要:linux系统中条件测试语句分为4类: 1、文件测试语句 2、逻辑测试语句 3、整数值比较语句 4、字符串比较语句 一、文件测试语句 -e :是否存在 -f :是否为文件 -d:是否为目录文件 -r:是否具有读的权限 -w: 是否具有写的权限 -x:是否具有执行的权限 [root@PC3 test]
阅读全文
摘要:1、基本shell脚本 #!/bin/bash command 2、参数的变量 $0:脚本名称 $#:参数的数目 $*:参数 $1:第一个参数 $2:第二个参数 $3:第三个参数 $?:上一条命令执行成功输出0,否则其他数字。 [root@PC3 test]# cat a.sh #!/bin/bas
阅读全文
摘要:1、read从键盘读入 [root@centos7 test]# echo $a [root@centos7 test]# read a 123456 [root@centos7 test]# echo $a 123456 2、-p 参数 加入提示 [root@centos7 test]# unse
阅读全文
摘要:1、测试for cat [root@PC3 test]# cat a.txt 01 02 03 06 07 08 11 12 13 16 17 18 [root@PC3 test]# for i in `cat a.txt`; do echo $i ; done 01 02 03 06 07 08
阅读全文
摘要:1、测试数据 [root@PC3 test]# cat a.txt e i e s d e t q s g e g 2、 [root@PC3 test]# cat a.txt e i e s d e t q s g e g [root@PC3 test]# sed 's/ /\n/g' a.txt
阅读全文
摘要:1、while语句 #include <stdio.h> int main(void) { int i = 2, j; puts("please input an integer."); do { printf("j = "); scanf("%d", &j); if (j <= 2) puts("
阅读全文
摘要:linux系统中sort命令。 1、测试数据 [root@centos7 test2]# cat a.txt google 110 5000 baidu 100 5000 guge 50 3000 sohu 100 4500 2、默认按照第一列排序 [root@centos7 test2]# sor
阅读全文
摘要:1、 [root@centos7 test]# ls a.txt [root@centos7 test]# cat a.txt i e s m u w e i p q x z u n k e c b v y [root@centos7 test]# sed 's/.$//' a.txt i e s
阅读全文