vieyahn2017 / shellv

shell command test and study
4 stars 1 forks source link

11.14 Shell命令目录文件4种复制方法 #62

Closed vieyahn2017 closed 3 years ago

vieyahn2017 commented 4 years ago

shell 命令目录文件4种复制方法 https://blog.csdn.net/Tong_zhi/article/details/80905270

vieyahn2017 commented 3 years ago

把/oldboy目录及子目录下面 所有以.sh结尾的文件复制到 /tmp下面 手续创建环境:

mkdir -p /oldboy/test cd /oldboy echo "oldboy">test/del.sh echo "oldboy">test.sh echo "oldboy">t.sh touch oldboy.txt touch alex.txt

这里写图片描述

接下来进行实际复制:

方法1:cp +$() cp $(find /oldboy/ -type f -name ".sh") /tm 方法2:find +|xargs -i find -type f -name ".sh" | xargs -i cp {} /tmp 主要使用了xargs的 -i 参数 配合使用{} 完成要求

方法3:find -exec find -type f -name "*.sh" -exec cp {} /tmp \; 使用了find 的 -exec参数 也是通过使用{} 完成要求

方法4: find +|xargs cp -t find -type f -name "*.sh" | xargs cp -t /tmp