AnonymousNamefag

randcopy

Dec 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.65 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # Don't ask me why I wrote this.
  3. # Suffice to say I'm a total sperg.
  4.  
  5. # Setup
  6. mkdir subset_dir
  7. ls -1 > list.txt
  8.  
  9. # Create list of 30 random files
  10. for ((i=0; $i<30; i++)); do
  11.     declare -i length=$(wc -l list.txt | cut -d ' ' -f 1)
  12.     declare -i r=$RANDOM%$length+1
  13.     sed -n "${r}p" list.txt >> sublist.txt
  14. done
  15.  
  16. # Remove dublicates
  17. cat sublist.txt | sort | uniq > subsublist.txt
  18. let length=$(wc -l subsublist.txt | cut -d ' ' -f 1)
  19.  
  20. # Copy files from list
  21. for ((i=1; $i<=$length; i++)); do
  22.     file=$(sed -n "${i}p" subsublist.txt)
  23.     cp $file subset_dir
  24. done
  25.  
  26. # Cleanup
  27. rm list.txt sublist.txt subsublist.txt
  28. unset i length file
Add Comment
Please, Sign In to add comment