콘텐츠로 이동


Urandom기반의 랜덤텍스트 생성

/dev/urandom 기반으로 랜덤한 문자열 생성

  1. 대소문자/숫자 조합으로 8자리 문자열 생성
    $> cat test.sh
    #!/bin/bash
    
    random_char=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | sed 1q)
    echo $random_char
    
    $> ./test.sh
    Y6cJfCwk
    $> ./test.sh
    ie3L5AYO
    $> ./test.sh
    ICEgcZib
    
  2. 대소문자/숫자/특수문자 조합으로 8자리 문자열 생성
    $> cat test.sh
    #!/bin/bash
    
    random_char=$(base64 /dev/urandom | head -1)
    char={%random_char: -8}
    echo $char
    
    
    $> ./test.sh
    Yi9+t7Aa
    $> ./test.sh
    /lUAJl2a
    $> ./test.sh
    Tm90IGIa
    

reference







작성일: 2026년 7월 11일 ,  마지막 업데이트: 2026년 7월 14일