如果系统存在文件名相同,但路径不同的文件,如果单纯用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
Gentoo Chrome浏览器在Linux root 权限下启动发生 user-data-dir修正Linux系统命令su和su - 区别验证相关资讯 shell Shell脚本
- 在shell脚本中使用函数 (今 11:53)
- 使用shell批量生成数据整合式迁移 (03月29日)
- shell脚本中报错dirname:无效选项 (12/21/2015 19:12:37)
| - Shell脚本 入门 —— 符号篇 (08月16日)
- Linux入门学习:认识shell和bash (03月25日)
- shell脚本:监控MySQL服务是否正常 (11/19/2015 20:05:43)
|
本文评论 查看全部评论 (0)