Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carloscabo/dc61e58a1ab37b148b0bf8a5574db979 to your computer and use it in GitHub Desktop.
Save carloscabo/dc61e58a1ab37b148b0bf8a5574db979 to your computer and use it in GitHub Desktop.
# Randomly copy certain amount of certain file type from one directory into another
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment