shell遗漏

1、
[root@host50 ~]# var1=redhat
[root@host50 ~]# echo $var1
redhat
[root@host50 ~]# echo $var17

[root@host50 ~]# echo ${var1}7
redhat7
[root@host50 ~]# echo $var1 87.4
redhat 87.4


2、
[root@host50 ~]# echo $shell

[root@host50 ~]# echo $SHELL
/bin/bash
[root@host50 ~]# echo $PS1
[\u@\h \W]\$
[root@host50 ~]# echo $PS2
>
[root@host50 ~]# ls \
> /etc/fstab
/etc/fstab


3、
[root@host50 ~]# grep '/sbin/nologin' /etc/passwd | wc -l
36
[root@host50 ~]# grep -c '/sbin/nologin' /etc/passwd
36


4、
[root@host50 ~]# time grep '/sbin/nologin' /etc/passwd | wc -l
36

real    0m0.004s
user    0m0.001s
sys    0m0.002s


5、查看当前系统是不是64位的
[root@host50 ~]# lscpu | grep x86_64
Architecture:          x86_64

6、
[root@host50 ~]# echo $[RANDOM%33+1]
20
[root@host50 ~]# echo $[RANDOM%33+1]
5
[root@host50 ~]# echo $[RANDOM%33+1]
26
[root@host50 ~]# echo $[RANDOM%33+1]
2
[root@host50 ~]# echo $[RANDOM%33+1]
12

7、
[root@host50 ~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
2.5*2.5
6.2
scale=2
2.5*2.5
6.25
1.11*1.11
1.23
scale=4
1.11*1.11
1.2321
quit
[root@host50 ~]#

8、
[root@host50 ~]# x=24
[root@host50 ~]# let x++
[root@host50 ~]# echo $x
25
[root@host50 ~]# let x+=10
[root@host50 ~]# echo $x
35
[root@host50 ~]# let x--
[root@host50 ~]# echo $x
34
[root@host50 ~]# let x=x+1
[root@host50 ~]# echo $x
35

9、
[root@server0 ~]# seq 10 | tr '\n' " "
1 2 3 4 5 6 7 8 9 10 [root@server0 ~]#

10、
vim 1.sh
#!/bin/bash
for ((i=1;i<=10;i+=2))
do
echo $i
done
[root@server0 ~]# chmod +x 1.sh
[root@server0 ~]# ./1.sh
1
3
5
7
9


11、
[root@server0 ~]# uuidgen-------随机生成一串唯一的字符
b616351a-4a39-4d62-a614-63184ea0c9fd

12、[root@server0 ~]# dirname /var/www/html------获取目录结构到倒数第二层
/var/www
[root@server0 ~]# basename /var/www/html
html
[root@server0 ~]# dirname /var/lib/nginx/conf/nginx.conf
/var/lib/nginx/conf
[root@server0 ~]# basename /var/lib/nginx/conf/nginx.conf
nginx.conf

12、
[root@room9pc01 ~]# echo hello the world > 1.txt
[root@room9pc01 ~]# cat 1.txt
hello the world
[root@room9pc01 ~]# sed -r 's/(.)(.)(.*)(.)(.)$/\1\4\3\2\5/' 1.txt
hlllo the wored


13、
[root@room9pc01 ~]# echo hello,root:world、jfdk:fdjkl | awk -F[,:、] '{print $2,$4,$5}'
root jfdk fdjkl


14、
[root@room9pc01 ~]# awk -F: 'BEGIN{print "用户名","uid","家目录"}{print $1,$3,$6}END{print "总用户数:",NR}' /etc/passwd
用户名 uid 家目录
root 0 /root
bin 1 /bin
daemon 2 /sbin
adm 3 /var/adm
tom 1006 /home/tom
jack 1007 /home/jack
总用户数: 52

15、
[root@room9pc01 ~]# seq 200 | awk  '$1%3==0'|  wc -l
66
[root@room9pc01 ~]# seq 200 | awk  '$1%3==0'| sed -n '$='
66
[root@room9pc01 ~]# seq 200 | awk  '$1%3==0'| awk '{}END{print NR}'
66

16、
[[root@room9pc01 ~]# awk 'BEGIN{a[0]=0;a[1]=11;a[2]=22;for(i in a){print i,a[i]}}'
0 0
1 11
2 22

猜你喜欢

转载自blog.csdn.net/Perfect11_1/article/details/81459638