Skip to content

Instantly share code, notes, and snippets.

@erikson1970
Last active November 12, 2025 03:39
Show Gist options
  • Select an option

  • Save erikson1970/afa1de85ce09b6e28fd71d5f9011c890 to your computer and use it in GitHub Desktop.

Select an option

Save erikson1970/afa1de85ce09b6e28fd71d5f9011c890 to your computer and use it in GitHub Desktop.
Random useful Command line things

Create random word filenames

create random filename prefix with 2 random words of random lengths

for i in $(shuf -n 2 /usr/share/dict/words); do printf "%s_" $i;done

Robert_Aspidoganoidei_
lifeless_disloyally_

create filename prefix with 2 five-letter random words

kk="four";for ((i=0;i<2;i++)); do while [ ${#kk} -ne 5 ];do kk=$(shuf -n 1 /usr/share/dict/words);done;printf "%s_" $kk;kk="four";done ; echo

jacal_gravy_
vapid_hilus_

create filename prefix with one five-letter random word

kk="four";while [ ${#kk} -ne 5 ];do kk=$(shuf -n 1 /usr/share/dict/words);done;echo $kk

henna
roost
snake

Create incrementing rotating log files

create filenames with counter and timestamps 100 lines each

  • create 100 line log files, rotate filenames with counter and timestamp
    cat ~/.bash_history | awk 'NR % 100 == 1 {close(f); f=sprintf("logfile_%04d_%s.txt.gz", ++i,"'"$(date +%Y%m%d_%H%M%S)"'"); cmd="gzip > " f} {print | cmd}'
$ ls -alrth
logfile_0002_20251111_220929.txt.gz
logfile_0003_20251111_220929.txt.gz
logfile_0004_20251111_220929.txt.gz
logfile_0005_20251111_220929.txt.gz

create filenames with counter at 100 lines each


cat ~/.bash_history | awk 'NR % 100 == 1 {close(f); f=sprintf("logfile_%04d.txt.gz", ++i); cmd="gzip > " f} {print | cmd}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment