我如何可以选择在bash目录随机文件? [英] How can I select random files from a directory in bash?
本文介绍了我如何可以选择在bash目录随机文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有大约2000文件的目录。我怎样才能选择 N
文件进行随机抽样,通过使用一个bash脚本或者管道命令的列表?
I have a directory with about 2000 files. How can I select a random sample of N
files through using either a bash script or a list of piped commands?
推荐答案
下面是一个使用GNU排序是随机选择的脚本:
Here's a script that uses GNU sort's random option:
ls |sort -R |tail -$N |while read file; do
# Something involving $file, or you can leave
# off the while to just get the filenames
done
这篇关于我如何可以选择在bash目录随机文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文