Skip to content

use shuf to choose a random file

Naohiro Aota fstests linux-btrfs 2 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 6 repliesIn review
  2. v23 patches 1 replySuperseded

Changes from the cover letter

- v2
- Introduce _random_file() helper
- Rewrite other "sort -R" with _random_file() or "shuf"
- v3
- Fix _random_file() helper to add the base directory as prefix

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3common/rc: introduce _random_file() helpercommon/rc+7 -04 replies
2/3fstests/btrfs: use _random_file() helpertests/btrfs/179 tests/btrfs/192+8 -151 reply
3/3btrfs/004: use shuf to shuffle the file linestests/btrfs/004+1 -11 reply

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchAnand Jain
1/3R-b
2/3R-b
3/3R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/3] use shuf to choose a random file

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".

Changes:
- v2
- Introduce _random_file() helper
- Rewrite other "sort -R" with _random_file() or "shuf"
- v3
- Fix _random_file() helper to add the base directory as prefix

Naohiro Aota (3):
common/rc: introduce _random_file() helper
fstests/btrfs: use _random_file() helper
btrfs/004: use shuf to shuffle the file lines

 common/rc       |  7 +++++++
 tests/btrfs/004 |  2 +-
 tests/btrfs/179 |  9 ++++-----
 tests/btrfs/192 | 14 ++++----------
 4 files changed, 16 insertions(+), 16 deletions(-)
Signature · 1 line
2.41.0