Message ID | cover.1692599767.git.naohiro.aota@wdc.com (mailing list archive) |
---|---|
Headers | show |
Series | use shuf to choose a random file | expand |
On Mon, Aug 21, 2023 at 03:37:01PM +0900, Naohiro Aota wrote: > Currently, we use "ls ... | sort -R | head -n1" (or tail) to choose a > random file in a directory.It sorts the files with "ls", sort it randomly > and pick the first line, which wastes the "ls" sort. > > Also, using "sort -R | head -n1" is inefficient. Furthermore, even without > "head" or "tail", "shuf" is faster than "sort -R". > > This series introduces a new helper _random_file() to choose a file in a > directory randomly. Also, replace "sort -R" with _random_file() or "shuf". Please discard this version. The _random_file() helper doesn't have the base directory prefixed. So, the btrfs/192 didn't work well. I'll revise it soon.