Skip to content

Instantly share code, notes, and snippets.

@nik-hil
Created September 1, 2018 10:20
Show Gist options
  • Save nik-hil/eb5f1b2b2b9983dfa653fd3df9d4a0b7 to your computer and use it in GitHub Desktop.
Save nik-hil/eb5f1b2b2b9983dfa653fd3df9d4a0b7 to your computer and use it in GitHub Desktop.
bash script to shuffle and copy
https://unix.stackexchange.com/a/217720
shuf -zn<count> -e *.<file_ext_in_curnt_dir> | xargs -0 cp -vt <target_dir>
shuf -zn8 -e *.jpg | xargs -0 cp -vt target/
shuf shuffles the list of *.jpg files in the current directory.
-z is to zero-terminate each line, so that files with special characters are treated correctly.
-n8 exits shuf after 8 files.
xargs -0 reads the input delimited by a null character (from shuf -z) and runs cp.
-v is to print every copy verbosely.
-t is to specify the target directory.
@nik-hil
Copy link
Author

nik-hil commented Sep 1, 2018

https://stackoverflow.com/a/12978830/618018

Use python to shuffle

import random

a = range(5)
b = random.sample(a, len(a))
print a, b, "two list same:", a == b
# print: [0, 1, 2, 3, 4] [2, 1, 3, 4, 0] two list same: False

# The function sample allows no duplicates.
# Result can be smaller but not larger than the input.
a = range(555)
b = random.sample(a, len(a))
print "no duplicates:", a == list(set(b))

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