shell实现拷贝目录的子目录下的文件夹和文件到另一目录下

时间:2020-05-30 17:30:31   收藏:0   阅读:305

功能:把/d/tmp1/里的tmp2及其子目录ttt和文件abc.html拷贝到目录/d/tmp/

实现代码

#!/bin/bash
for subm in `ls /d/tmp1`; do
echo $subm
  for file in `ls /d/tmp1/$subm`;do
  echo $file
  cp -rf /d/tmp1/$subm/$file /d/tmp/
  done
done

输出:

$ ls -l /d/tmp1/
total 0
drwxr-xr-x 1 brian 197121 0 5月 30 16:16 tmp2/

$ ls -l /d/tmp/
total 0

$ sh abc.sh
tmp2
abc.html
tta
ttt

$ ls /d/tmp
abc.html bbb.html tta/ ttt/

 

也可增加该文件是目录还是文件的判断。

原文:https://www.cnblogs.com/v5captain/p/12993475.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!