shell实现文件名相同路径不同的批量复制
如果系统存在文件名相同,但路径不同的文件,如果单纯用find来批量复制到一个地方的话会被覆盖掉,下面的脚本是实现根据文件名的路径来进行存放复制。为能更好的测试,脚本中加了在不同路径创建相同文件名的程序。
- #!/bin/sh
- . /etc/profile
- # define
- tf=testfile
- destpath=/root/found
- [ ! -d $destpath ] && mkdir -p $destpath
- # touch some the same file for test
- TouchFile()
- {
- echo "/tmp" > /tmp/$tf
- echo "/home" > /home/$tf
- echo "/root" > /root/$tf
- echo "/var/tmp" > /var/tmp/$tf
- }
- # find the file and copy to the dest dir
- FindCopy()
- {
- TouchFile
- if [ $? -eq 0 ];then
- for i in $(find / -name $tf);do
- [ ! -d $destpath/$(dirname $i) ] && mkdir -p $destpath$(dirname $i)
- cp -rf $i $destpath$(dirname $i)
- #echo $i
- done
- else
- echo "please touch some test file first..."
- fi
- }
- FindCopy
相关推荐
卖口粥湛蓝的天空 2020-09-15
huha 2020-10-16
laisean 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
JohnYork 2020-10-16
Julyth 2020-10-16
applecarelte 2020-10-16
laisean 2020-09-27
flycappuccino 2020-09-27
liguojia 2020-09-27
wangzhaotongalex 2020-09-22
流年浅滩 2020-10-23
liujianhua 2020-10-22
woaimeinuo 2020-10-21
tufeiax 2020-09-03
laisean 2020-09-01
vvu 2020-09-16
libao 2020-09-16
Yyqingmofeige 2020-08-18
zhushixia 2020-08-17