2025年Linux的shuf命令

Linux的shuf命令shuf 随机排序 待扩展 gt Linux 下的随机数生成和排序方法 包含各类 shell 和 sort 有时候在 Linux 中我们需要各种各样符合要求的的随机数 最主要和最常用做法是写个 shell 利用 bash 里的内置变量 RANDOM 进行排序 然后打印 细节待补充 1 安装

大家好,我是讯享网,很高兴认识大家。

shuf 随机排序

待扩展->Linux下的随机数生成和排序方法,包含各类shell和sort 

讯享网

1.安装

yum install coreutils

brew install coreutils


讯享网

apt install coreutils

进行安装。

2.详情
它能够接受标准输入,即管道。

讯享网man页给出的使用方法如下: NAME shuf - generate random permutations SYNOPSIS shuf [OPTION]... [FILE] shuf -e [OPTION]... [ARG]... shuf -i LO-HI [OPTION]... DESCRIPTION Write a random permutation of the input lines to standard output. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too. -e, --echo treat each ARG as an input line -i, --input-range=LO-HI treat each number LO through HI as an input line -n, --head-count=COUNT output at most COUNT lines -o, --output=FILE write result to FILE instead of standard output --random-source=FILE get random bytes from FILE -r, --repeat output lines can be repeated -z, --zero-terminated line delimiter is NUL, not newline --help display this help and exit --version output version information and exit 

其中常用参数:

 -i 写入范围 -n 最多显示多少行 -o 将随机排序后的输出写到一个文件中 

3.例子
假设需要生成3个范围为0-200的随机数到文件rand.txt中,只需要如下操作即可,效率:

shuf -i 0-200 -n 3 -o rand.txt

当然这个也是有不足之处的,比如,它并不是严格意义上的随机数。但是可以满足一些非专业和严格要求的需要。【具体细节待补充】

参考来源:

  1. shuf 命令:随机排序文件:https://blog.csdn.net/reyleon/article/details/
小讯
上一篇 2025-01-12 09:47
下一篇 2025-01-14 08:16

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/122825.html