Unix:ls 到 select 所有文件,但顺序是随机的?
Unix: ls to select all files, but in a random order?
由于 ls
return 文件是按字母顺序排列的,有没有办法 return 以随机顺序排列相同的文件?我正在尝试遍历目录中的所有文件,但希望它在不同的运行中有所不同。
for i in *.py # Would like order to be random
do
...
done
这是 randomly shuffling files in bash and How can I shuffle the lines of a text file on the Unix command line or in a shell script?
的副本
但是,这应该可以完成工作:
for i in `ls *.py | shuf`
do
echo $i
done
由于 ls
return 文件是按字母顺序排列的,有没有办法 return 以随机顺序排列相同的文件?我正在尝试遍历目录中的所有文件,但希望它在不同的运行中有所不同。
for i in *.py # Would like order to be random
do
...
done
这是 randomly shuffling files in bash and How can I shuffle the lines of a text file on the Unix command line or in a shell script?
的副本但是,这应该可以完成工作:
for i in `ls *.py | shuf`
do
echo $i
done