移动文件夹后ln原文件夹

需求描述

A文件夹内有3000个文件夹,分别为文件夹1,文件夹2,。。。。文件夹2999.

需要

1)把3000个文件夹移动到B文件夹,

2)在A文件夹内建立3000个link,link到B文件夹中的文件夹。

#! /bin/bash #code mysrc2dst.sh by Jevons Zeng #2009-05-20 SRCPRE=/src DESTPRE=/dest FROMNUMBER=0 TONUMBER=3000 if [ $SRCPRE = $DESTPRE ]; then echo "error=the first parameter can not eq the seconde parameter!" exit 1 fi #check src_pre_directory dst_pre_directory if test -e $SRCPRE; then echo "find $SRCPRE" else echo "error=the first parameter $SRCPRE error,directory doesn't exist!" exit 1 fi if test -e $DESTPRE; then echo "find $DESTPRE" else echo "error=the second parameter $DESTPRE error,directory doesn't exist!" exit 1 fi DESTSTOREDIR=$DESTPRE echo "we will mv directory from $SRCPRE to $DESTSTOREDIR" for((i=$FROMNUMBER;i<=$TONUMBER;i++)) do #1)cp from srcdir to dstdir #2)mv srcdir to srcdir.bak #3)rm -rf srcdir #3)ln -s dstdir to srcdir #4)rm -rf srcdir.bak SRCDIR="$SRCPRE/$i" DESTDIR="$DESTSTOREDIR/$i" if test -e $SRCDIR; then if ls -l $SRCDIR | egrep $DESTSTOREDIR; then echo "$i have been link,you don't need link again!" else cp -rf $SRCDIR $DESTDIR mv $SRCDIR $SRCDIR.bak rm -rf $SRCDIR ln -s $DESTDIR $SRCDIR #rm -rf $SRCDIR.bak echo "finish $i link!" fi else echo "error=can not find the directory $SRCDIR" fi done echo "all finish"

你可能感兴趣的:(移动文件夹后ln原文件夹)