Is there an elegant and fast way to copy a certain directory structure and only select a random amount of files to be copied with it. So for example you have the structure:--MainDir  --SubDir1    --SubSubDir1      --file1      --file2      --...      --fileN    --...    --SubSubDirN      --file1      --file2      --...      --fileN  --...I want to copy the entire folder structure but choose only a specific number of random files from {files1-filesN} of each SubSubDir to be copied along.
Copy directory structure with random number of files
linux;file copy
Since you tagged this as linux I'll assume GNU utilities.Copy directory structure from $src to $dest:find $src -type d -print0 | cpio -padmv0 $destAlso copy a random sample of $nfile files from each leaf subdirectory of $src:find $src -type d -links 2 -exec \    sh -c 'find $1 -type f -print0 | shuf -z -n $2' sh {} $nfiles \; | \    cpio -padmv0  $destHere the first find finds leaf subdirectories (-links 2), then the second find finds files in each of these subdirectories.  shuf chooses a random sample of files, and finally cpio copies them.