考虑以下目录
/tmp/dit
$ tree
.
|-- files.txt
|-- r_1
|-- r_2
`-- r_3
$ cat files.txt
a
b
c
find
将每个文件移动到
随机的
filex.txt
文件,我使用以下命令;
find . -not -iname '*.txt' -type f -exec mv {} $(shuf -n 1 files.txt) \;
不幸的是
command substitution
只执行一次,导致
全部的
正在移动到的文件
问题
:是吗
是否有选项确保为每个文件调用命令替换?
我设法用了一个
while; do
循环以确保每次都执行命令替换,但是由于我的实际情况要复杂得多,所以我希望找到一个解决方案
仅使用
找到
find . -not -iname '*.txt' -type f -print0 | while read -d $'\0' file
do mv "$file" "$(shuf -n 1 /tmp/dit/files.txt)"
done