击:遍历一个文本文件中列出并移动文件 [英] Bash: Loop over files listed in a text file and move them

查看:108
本文介绍了击:遍历一个文本文件中列出并移动文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目录(目录A)在其10,000个文件。我想他们中的一些移动到目录B和别人目录C.我做了一个包含所有我想要移动到目录B中的文件的名称和另一个与所有我想要的文件的文件名的文本文件移动到目录C.我如何写for循环将这些文件移动到新目录中一个bash。

伪code:

在textfileB文件:结果
   摆脱目录里的文件目录B中

在textfileC文件:结果
   摆脱目录中的文件路径:C

很抱歉,如果这是问其他地方,但我花了几个小时努力学习bash和我只是不明白这一点。我没能找到另一个线程我能理解(也许我只是不知道正确的搜索词)足够的类似的东西。

我有这样的事情,但我无法得到它的工作:

  FILES = [不要'知道放在这里?数组?一个列表?

我可以只陈述文字的文件名,如果是什么格式做的文件要? name1.ext,name2.ext或name1.ext name2.ext]

 在$ FILES F;做MV $ F / B / $ F [不知道有关MV的第二个参数] DONE

THX

BTW
的Mac OSX 10.6.8(雪豹)
苹果终端诉2.1.2 / 273.1
巴什3.2


解决方案

 猫文件LIST.TXT |而读我;做
   #TODO:你的MV命令在这里。 $ I将是从线
   #文本文件。
DONE

I have a directory (directory A) with 10,000 files in it. I want to move some of them to directory B and the others to directory C. I made a text file that contains the names of all the files I want to move to directory B and another one with the names of all the files that I want to move to directory C. How can I write a bash for loop to move these files to the new directories.

Pseudocode:

for file in textfileB:
move file from directory A to directory B

for file in textfileC:
move file from directory A to directory C

Sorry if this is asked somewhere else, but I've spent hours trying to learn bash and I just don't get it. I wasn't able to find something similar enough in another thread that I could understand (maybe I just don't know the right search words).

I got something like this, but I couldn't get it working:

FILES=[dont' know what goes here? An array? A list?  

Can I just state the text file name and if so what format do the files have to be? name1.ext, name2.ext, or name1.ext name2.ext]

for f in $FILES; do mv $f /B/$f [not sure about the second argument for mv]; done

thx

BTW Mac OSX 10.6.8 (Snow Leopard) Apple Terminal v. 2.1.2 / 273.1 Bash 3.2

解决方案

cat file-list.txt | while read i; do
   # TODO: your "mv" command here.  "$i" will be a line from
   # the text file.
done

这篇关于击:遍历一个文本文件中列出并移动文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆