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 展开
/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 展开
4个回答
展开全部
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
追答
这个脚本应该可以
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
每天都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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询