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/
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.