
12 Sep
2024
12 Sep
'24
2:59 p.m.
Hi everyone I was just wondering how I can copy a random subset of files from one folder to another. And, of course, there bash utilities for that... ;-) I came across two solutions for copying 20 files from the current directory into DEST: - shuf cp `ls | shuf -n 20` DEST - sort (using random sort) ls | sort -R | tail -20 | while read file do cp $file DEST done source: https://stackoverflow.com/questions/414164/ Man pages: - shuf: https://www.man7.org/linux/man-pages/man1/shuf.1.html - sort: https://man7.org/linux/man-pages/man1/sort.1.html Cheers, Peter