@mrz1
2017-12-26T13:41:06.000000Z
字数 2771
阅读 1289
面试题
[root@centos7 ~]#color=`seq 31 37|sort -R|head -1`;echo -e "\033[${color}mred color\033[0m"red color
1.1 用vim编写带颜色的字:
1. ctrl+v+[2. [3. 颜色4. 内容5.ctrl+v+[6. [7. 0m例子:[[31mred^[[0m必须用vim编写,如果不是,只会当做字符串显示,不会带颜色^[是控制符一个整体还有一种方法是echo 输进去
[root@centos7 ~]#echo {1..100} |tr ' ' '+'|bc -l //5050[root@centos7 ~]#seq -s + 1 100|bc
[root@centos7 ~]#expr 1 + 799 //expr也可以进行运算800
[root@centos6 ~]#for (( sum=0,i=1;i<=100;i++ ));do let sum+=i;done ;echo $sum5050
[root@centos6 ~]#for (( sum=0,i=0;i<=100;i+=3 ));do let sum+=i;done ;echo $sum1683
[root@centos6 ~]#sum=0;for i in {0..100..3};do let sum+=i;done;echo $sum1683
[root@centos6 ~]#sum=0;i=0;while [ $i -le 100 ]; do let sum+=i;let i+=3;done;echo sum=$sumsum=1683
var=haha123 ; [[ "$var" =~ ^[0-9]+$ ]] && echo true || echo false
var=0123 ; [[ "$var" =~ ^0*[1-9][0-9]*$ ]] && echo true || echo false
mobile=12800138000 ;[[ "$mobile" =~ ^1[3456789][0-9]{9}$ ]] && echo true || echo false
[root@centos7 ~]#ip="123.23.223.23";[[ "$ip" =~ (([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]) ]] && echo true ||echo falsetrue
var=haha123 ; [[ "$var" =~ ^[0-9]+$ ]] && echo true || echo false
var=0123 ; [[ "$var" =~ ^0*[1-9][0-9]*$ ]] && echo true || echo false
mobile=12800138000 ;[[ "$mobile" =~ ^1[3456789][0-9]{9}$ ]] && echo true || echo false
[root@centos7 ~]#cat checkdisk.sh#! /bin/bash# ------------------------------------------# Filename: checkdisk.sh......省略# ------------------------------------------echo "鸡兔同笼问题?"read -p "请输入头:" headread -p "请输入脚:" footc=$[( foot - head*2 ) /2 ]r=$[ head - $c ]echo "兔子:$c"echo "鸡: $r"
[root@centos6 app]#cat f1aefcd[root@centos6 app]#cat f2acbcggd[root@centos6 app]#grep -f f2 f1 //把f2当成搜索条件去f1里面找交集acd
[root@centos7 ~]#openssl rand -hex 4 //第一种a856ece3[root@centos7 ~]#openssl rand -base64 10|head -c 8 //第二种kuO114wH[root@centos7 ~]#cat /dev/random |tr -dc 'a-zA-Z0-9'|head -c8 //第三种Iv2uUkHQ
for ((i=1;i<=9;i++));do for ((j=1;j<=i;j++));do echo -ne "${j}x${i}=$[$i*$j]\t";done;echo;done
ntpdate ip地址
例ntpdate 127.0.0.0 同步一次127.0.0.0服务器时间
永久同步时间需要修改/etc/ntp.conf

永久同步时间需要修改/etc/ntp.conf[root@centos6 ~]#chkconfig --list ntpdntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off[root@centos6 ~]#chkconfig ntpd on[root@centos6 ~]#chkconfig --list ntpdntpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off[root@centos6 ~]#service ntpd startStarting ntpd: [ OK ]
7
永久同步时间需要修改/etc/ntp.conf[root@centos7 ~]systemctl status ntpd● ntpd.service - Network Time ServiceLoaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)Active: inactive(无效的) (dead)[root@centos7 ~]#systemctl is-enabled ntpddisabled(禁用)[root@centos7 ~]#systemctl enable ntpdCreated symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.[root@centos7 ~]#systemctl start ntpd[root@centos7 ~]#systemctl status ntpd● ntpd.service - Network Time Service.....