linux 如何把各文件夹下的txt文件copy到另一个文件夹中

目录有规律:/mnt/disk1/flume/test/huatong/picture/20140116/9/mnt/disk2/flume/test/huatong/p... 目录有规律:
/mnt/disk1/flume/test/huatong/picture/20140116/9
/mnt/disk2/flume/test/huatong/picture/20140116/9
/mnt/disk3/flume/test/huatong/picture/20140116/9
/mnt/disk4/flume/test/huatong/picture/20140116/9
……
……
这些目录的差别就是disk1,disk2,disk3,disk4,disk5的区别
[root@HTCDN-ZJHZ-NOC-CLOUD-09 ~]# cd /mnt/disk4/flume/test/huatong/picture/20140116/9
该文件夹下有6个子目录
[root@HTCDN-ZJHZ-NOC-CLOUD-09 9]# ll
总用量 20
drwxr-xr-x 2 root root 4096 2月 13 04:54 001
drwxr-xr-x 2 root root 4096 2月 12 20:37 002
drwxr-xr-x 2 root root 4096 2月 13 04:54 003
drwxr-xr-x 2 root root 4096 2月 12 20:37 004
drwxr-xr-x 2 root root 4096 2月 13 04:54 006
把这些txt都copy到/opt/test目录下
[root@HTCDN-ZJHZ-NOC-CLOUD-09 9]# find . -name *txt
./001/huatong-HZ001HZLA02-1389804016599.snappy.txt
./003/huatong-HZ003CEN006-1389804009842.snappy.txt
./006/huatong-HZ006HZLP01-1389804013674.snappy.txt
求简便的方法,最好是脚本
求脚本大神帮个忙
for i in {1..8}; do find /mnt/disk$i/flume/test/huatong/picture/20140116/9 -name *.txt |xargs -i cp -rf {} /opt/test/.; done
展开
 我来答
墨紫音
推荐于2017-09-29 · TA获得超过1.8万个赞
知道大有可为答主
回答量:2390
采纳率:56%
帮助的人:1017万
展开全部
cp 不带参数,只能copy一个文件,不能copy带文件的目录,到指定地方.

cp -rf 带参数,就能copy任何数据,到指定地方.

比如:cp test.txt /home/MIR1566-PC/Document 拷贝test文本文件到指定目录下.

比如:cp -rf test /home/MIR1566-PC/Document 拷贝test目录到指定目录下.
百度网友5311d79
2014-02-14 · TA获得超过1.9万个赞
知道大有可为答主
回答量:6356
采纳率:71%
帮助的人:3091万
展开全部
find /mnt/disk?/flume/test/huatong/picture/20140116/9 -type f -name "*.txt" -exec cp {} /opt/test/ \;

 既然目录只是disk1,disk2,disk3,disk4,disk5的区别,那么用通配符表示就可以:disk?

追问
for i in {1..8}; do find /mnt/disk$i/flume/test/huatong/picture/20140116/9 -name *.txt |xargs -i cp -rf  {} /opt/test/.;  done
追答

这个貌似是有错误的,xargs中只有大写i 选项。试试下面这样:

for i in {1..8}; do  find /mnt/disk$i/flume/test/huatong/picture/20140116/9 -name *.txt | xargs -I cp -rf '{}' /opt/test/.;  done
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
nanmenqiang
2014-02-14 · TA获得超过275个赞
知道小有建树答主
回答量:134
采纳率:0%
帮助的人:105万
展开全部
find /mnt -name "*.txt" -type f -exec cp {} /opt/test/ \;
追问
for i in {1..8}; do find /mnt/disk$i/flume/test/huatong/picture/20140116/9 -name *.txt |xargs -i cp -rf  {} /opt/test/.;  done
追答
这个脚本应该可以
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
新媒体云
2014-02-14 · 超过31用户采纳过TA的回答
知道答主
回答量:174
采纳率:0%
帮助的人:76.7万
展开全部
每天都copy 么?每天文件目录不一样?
追问
for i in {1..8}; do find /mnt/disk$i/flume/test/huatong/picture/20140116/9 -name *.txt |xargs -i cp -rf  {} /opt/test/.;  done
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式