Answer the question
In order to leave comments, you need to log in
How to select random files from a folder?
There is a folder with a million files in it. You need to select random from a folder of 100 thousand files and copy them to another folder.
Can you please tell me how it can be done in the terminal?
Answer the question
In order to leave comments, you need to log in
Like this
#!/bin/bash
if ! [ $3 ];then
precent=6
else
precent=$3
fi
ls $1 > ls.log
while read line
do
[ $[ $RANDOM % $precent ] == 0 ] && cp -R $1/$line $2
done < ls.log
And you can write a script in bash, especially since the question section
is "BASH LINUX TERMINAL" :)
Using a random number generator in bash. For example, shuf -i 100000-999999 -n 100000
this will generate 100000 sl. numbers in the range from 100000 to 999999, which can be used to randomly select the files you need in a loop.
ls | shuf | tail | mv
Something like that. Collect the keys yourself according to man-s.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question