Pat*_*uad 9 macos bash for-loop file move
我有一个目录(目录A),其中包含10,000个文件.我想将其中一些移动到目录B,其他移动到目录C.我创建了一个文本文件,其中包含我要移动到目录B的所有文件的名称,另一个文件包含我想要的所有文件的名称移动到目录C.如何编写bash for循环以将这些文件移动到新目录.
伪代码:
对于textfileB中的文件:
将文件从目录A移动到目录B
对于textfileC中的文件:
将文件从目录A移动到目录C
对不起,如果这是在其他地方被问到,但我花了好几个小时试图学习bash而我却没有得到它.我无法在另一个我能理解的线程中找到类似的东西(也许我只是不知道正确的搜索词).
我有这样的东西,但我无法让它工作:
FILES=[dont' know what goes here? An array? A list?
Run Code Online (Sandbox Code Playgroud)
我可以只说明文本文件名,如果是,那么文件必须是什么格式?name1.ext,name2.ext或name1.ext name2.ext]
for f in $FILES; do mv $f /B/$f [not sure about the second argument for mv]; done
Run Code Online (Sandbox Code Playgroud)
谢谢
BTW Mac OSX 10.6.8(Snow Leopard)Apple Terminal v.2.1.2/273.1 Bash 3.2
asv*_*kau 22
cat file-list.txt | while read i; do
# TODO: your "mv" command here. "$i" will be a line from
# the text file.
done
Run Code Online (Sandbox Code Playgroud)