[英]Take limited files from directory and insert them into another directory
我的目录包含80.000个图像 ,我想使用Bash命令将该目录中的30.000个图像随机插入另一个目录。
假设您位于80000张图片所在的目录中,而另一个目录称为target,则此目录应该有效:
ls | shuf | head -n 30000 | xargs -i cp "{}" target/.
While the provided answer is correct shuf
is not installed on all systems so you might consider to use sort -R
instead. 尽管提供的答案正确,
shuf
不是在所有系统上都安装了shuf
因此您可以考虑使用sort -R
。 I quote the man page: 我引用手册页:
Sort by a random order.
按随机顺序排序。 This is a random permutation of the inputs except that the equal keys sort together.
这是输入的随机排列,除了相等的键排序在一起。 It is implemented by hashing the input keys and sorting the hash values.
它通过对输入键进行哈希处理并对哈希值进行排序来实现。 The hash function is chosen randomly.
哈希函数是随机选择的。 The hash function is randomized by /dev/random content, or by file content if it is specified by --random-source.
哈希函数由/ dev / random内容随机分配,如果由--random-source指定,则按文件内容随机分配。 Even if multiple sort fields are specified, the same random hash function is used for all of them.
即使指定了多个排序字段,也对所有它们使用相同的随机哈希函数。
As long as you do not have any duplicates (exactly the same file just with a different name) and you do not want to install shuf
or any other tool you can use this to get a 'random' sort. 只要您没有任何重复项(名称完全相同,只是文件名不同),并且您不想安装
shuf
或任何其他工具,就可以使用它来进行“随机”排序。
ls | sort -R | tail -n 30000 | xargs -I "{}" cp "{}" ./target
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.