1. 程式人生 > >shell 實戰11:迴圈遍歷

shell 實戰11:迴圈遍歷

顯示目錄:ls -F|grep /

顯示特定檔案::ls *.jpg

字串擷取分隔符前面的字元:echo 字串| cut -d "分隔符" -f1

字串擷取分隔符後面的字元:echo 字串| cut -d "分隔符" -f2

隨機數: echo $(date +%t%N)$RANDOM|md5sum|cut -c 2-9

[email protected] MINGW64 /d/Project/linuxWorkspace
$ echo $RANDOM
8614

[email protected] MINGW64 /d/Project/linuxWorkspace
$ echo $RANDOM|md5sum
89baaa9c1163fec2a3e1b83fba46c0c1 *-

[email protected] MINGW64 /d/Project/linuxWorkspace
$ echo $RANDOM|md5sum |cut -c 15-22
590d6111

[email protected] MINGW64 /d/Project/linuxWorkspace
$ echo "$RANDOM$(date +%U%t)"|md5sum |cut -c 15-22
a0970b3d

[email protected] MINGW64 /d/Project/linuxWorkspace
$ echo "$(date +%U%t)"
34

[email protected]

MINGW64 /d/Project/linuxWorkspace
$ echo "$(date +%N%t)"
817725100
 

[email protected] MINGW64 /d/Project/linuxWorkspace
$ openssl rand -base64 8
0q0n+bhFGxo=

[email protected] MINGW64 /d/Project/linuxWorkspace
$ openssl rand -base64 8|md5sum
2957ed02c2cb5b115406c8b6b046ab57 *-
 

[email protected]

MINGW64 /d/Project/linuxWorkspace
$ date +%s%N
1535267320420314100
 

$ head /dev/urandom|cksum
156634633 2317
[[email protected] ~]$ cat /proc/sys/kernel/random/uuid
82778a8b-d614-41d1-8c59-02d7e8402521

$ for n in `seq 20`;do echo $RANDOM|md5sum|cut -c 1-9|sort|uniq -c||sort -nk1;done
      1 e302c6c2a
      1 3fa6c3efb
      1 2d8b06ce6
      1 1133ef500
      1 690b6ee35
      1 464d04836
      1 700ab7d86
      1 4ee771a4e
      1 223b46917
      1 f64038855
      1 6b5fdcdce
      1 8089e9cbb
      1 580b65aef
      1 950f9e5eb
      1 f2f7ecbbf
      1 f590e59e7
      1 fb4078063
      1 21e0a16c3
      1 c0b60923b
      1 85ba9775f
 

$ for n in `seq 20`;do date +%s%N|md5sum|cut -c 1-9|sort|uniq -c|sort -nk1;done
      1 84bbf445f
      1 9a19e2602
      1 61f18f864
      1 1468e97cd
      1 90243aa10
      1 66a8781b4
      1 c7545bd7d
      1 019a07b93
      1 c274ab3e5
      1 398c06837
      1 5a1578857
      1 7d7c762f6
      1 3532437be
      1 b8fae2c87
      1 8a35cf89d
      1 e412e151e
      1 d003dbcd4
      1 cdab87033
      1 d00354da8
      1 f3c22f4b3
 

$ for n in `seq 20`;do date +%F|md5sum|cut -c 1-9|sort|uniq -c|sort -nk1;done
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
      1 5c8922cb0
$ for n in `seq 20`;do date +%F|md5sum|cut -c 1-9;done|sort|uniq -c
     20 5c8922cb0