How to move a given number of random files on Unix/Linux OS
Use a combination of shuf
and xargs
(it's a good idea to look at their documentation with man
):
shuf -n 10 -e * | xargs -i mv {} path-to-new-folder
The command above selects 10 random files of the current folder (the *
part) and then move them to the new folder.
Update
Although longer, one might find this version even simpler to understand:
ls | shuf -n 10 | xargs -i mv {} path-to-new-folder
shuf
just generates a random permutation of the standard input, limiting the results to 10 (like using head
, but probably faster).