shell脚本示例,复制名为dir1和dir2的目录下所有的文件到名为dir3的新目录
2018-02-26 14:43
706 查看
#! /bin/sh if [ $# -eq 3 ] then dir1=$1 dir2=$2 dir3=$3 if [ -d $dir1 -a -d $dir2 ] then if [ -d $dir3 ] then echo "$dir3 already exits" exit else cp -r -p $dir1 $dir3 echo -e "These files from $dir1 copied into $dir3: " list=`ls $dir3` echo $list ls $dir3 | sort > a.txt ls $dir2 | sort > b.txt comm a.txt b.txt -1 -3 > new.txt echo -e "\nThese new file(s) from $dir2 copied into dir3 " cat new.txt| while read line do cp -p $dir2/$line $dir3 echo $line done comm a.txt b.txt -1 -2 > old.txt echo -e "\nThese file(s) from $dir2 copied into $dir3 and overwrite(s) their namesakes in $dir3:" cat old.txt| while read line do mTimeDir1=`find $dir2 -name $line -printf "%AY-%Am-%Ad %AH:%AM:%AS"` mTimeDir2=`find $dir1 -name $line -printf "%AY-%Am-%Ad %AH:%AM:%AS"` t1=`date -d "$mTimeDir1" +%s` t2=`date -d "$mTimeDir2" +%s` if [ $t1 -lt $t2 ]; then cp -p $dir2/$line $dir3 echo $line fi done fi else echo "$dir1 or $dir2 not exits" exit fi else echo "Less Parameters" fi rm a.txt b.txt new.txt old.txt
相关文章推荐
- shell脚本----cp (copy)复制文件或目录
- Linux下使用Shell脚本删除一个目录下的所有子目录和文件
- shell脚本----cp (copy)复制文件或目录
- shell脚本----cp (copy)复制文件或目录
- Shell脚本:判断当前目录下所有的文件类型
- Shell脚本递归遍历目录所有文件
- shell小脚本实现上传目录中的所有文件到服务器
- shell脚本批量修改目录下所有文件中的部分语句
- 编写一个SHELL脚本,可以获得指定目录下的所有文件及文件夹的大小。输出的样式与 ls -lh 命令相同。
- shell脚本----cp (copy)复制文件或目录
- Shell脚本递归打印指定目录中所有目录文件
- shell 脚本,将/etc/目录下所有的软链接文件输出
- 得到所有目录与对目录下的文件进行操作的shell脚本
- linux下设计一个Shell脚本:判断当前工作目录下所有的文件类型。
- shell脚本-复制root目录下所有目录到tmp/下
- 利用shell脚本批量复制文件到给定目录
- shell脚本查找指定目录下所有子目录中的同名文件
- Linux监控系统磁盘使用比例,当使用率达到指定比例,删除指定目录下的所有文件的shell脚本
- shell脚本批量修改目录下所有文件中的部分语句
- shell脚本----cp (copy)复制文件或目录