Randomly select and move 500 directories/folders from a folder to another?

Viewed 230

I want to move/copy 500 folders from one directory to another. Here, I am not choosing the files randomly but directories/folders.

I used the following command to do it, but i am able to mv only a few folders and not 500 folders are moved. Any suggestions on the following command?

ls | shuf -n 500 | xargs -i mv {} /path-folder/
1 Answers

Use find -type d to select directories, shuf to randomize the order, and head -n 500 to select 500 random directories:

find . -mindepth 1 -maxdepth 1 -type d | shuf | head -n 500 | xargs -I{} mv {} dest_dir/

See also find manual for more details.

Related